﻿/*Load dữ liệu từ các table
        * 
        * 1.Catalogue_SchoolYear
        * 2.Catalogue_Term
        * 3.Training_ScoreType
        * 4.Training_Student
        * 5.Training_Student_Class
        * 6.Training_Student_Subject
        * 7.Training_Student_Subject_Class
        * 8.Training_Subject_Class
*/
/* Lưu dữ liệu vào table
        * 1.Training_Score
*/
/*Khác nhau giua Dai hoc - Trung cap
 * outputScore()
 * grvScore_CellValueChanged()
 * Label hien thi % cac loai diem: ham khoi tao Frm, button Edit, checkScoreTypeFinishInput
 * grvScore_ShowingEditor
 */
using System;
using System.Windows.Forms;
using UniMana.Utils.Data;
using DevExpress.XtraBars;
using System.Data;
using System.Linq;
using DevExpress.XtraEditors;
using System.Collections.Generic;
using UniMana.Utils.Controls;
using System.Data.OleDb;
using UniMana.Data;
using UniMana.Utils.Helper;
using UniMana.Utils.Configs;
using DevExpress.XtraGrid.Views.Grid;
using System.Drawing;
using System.Threading;

namespace UniMana.Win.Training
{
    public partial class FrmScore_Input : DevExpress.XtraEditors.XtraForm
    {
        #region [Declare variables]
        private DBMain m_data = new DBMain();
        private bds m_bds = new bds();
        //private DBTraining m_Catalogue = new DBTraining();
        private DataTable m_dtScore;
        private DataTable m_dtInfoStudent = new DataTable();
        private List<int> m_lScoreType = new List<int>();
        private ClsReadNumber m_cReadnumber = new ClsReadNumber();
        private bool m_bCanChange = false;
        private bool m_bCanEdit = false;
        private Guid m_gPersonelKey = Guid.Parse(UniMana.Utils.LoginInfo.GblLoginInfo.sysLoginPersionalKey.ToString());
        private int m_iScoreTypeLock;
        private bool m_bScoreTypeLock = false;
        private int m_iPosition = 0;
        private bool m_bFinishInput = false;
        private int m_iSubjectClassKey = 0;
        //
        private eFuncTions m_eType;
        private DataTable m_dtDraw = new DataTable();
        public enum eFuncTions
        {
            Check, Input, View
        }
        //
        private Thread m_tThread;
        private List<RowScore> m_lRowScore = new List<RowScore>();
        private List<float> m_lPpercent = new List<float>();
        //private bool m_bIsClosed = false;
        //
        private List<int> m_lCoefficient = new List<int>();
        //private bool m_bYearly = true;
        private double m_dMinScorePass;
        #endregion

        #region [Form Initialize]
        public FrmScore_Input()
        {
            InitializeComponent();
            InitControlEvent();
            xucBar1.btnSave.Enabled = false;
            xucBar1.btnCancel.Enabled = false;
            xucBar1.btnImportExcel.Enabled = false;
            xucBar1.btnAddNew.Visibility = BarItemVisibility.Never;
            xucBar1.btnDelete.Visibility = BarItemVisibility.Never;
        }
        public FrmScore_Input(string subjectClassID)
        {
            InitializeComponent();
            InitControlEvent();
            //LoadData();
            //txtSubjectClassID.EditValue = null;
            txtSubjectClassID.Text = subjectClassID;
            xucBar1.Enabled = false;
            //panelControl5.Visible = false;
            this.splitContainerControl1.Collapsed = true;
            btnLockAll.Visible = false;
            labelSubjectClassID.Text = "Bảng điểm lớp học phần: " + subjectClassID.ToString();
            int width = panelControl1.Width;
            labelSubjectClassID.Location = new System.Drawing.Point(width / 2 - labelSubjectClassID.Width / 2, labelSubjectClassID.Location.Y);
        }
        public FrmScore_Input(int _iSubjectClassKey)
        {
            InitializeComponent();
            InitControlEvent();
            m_iSubjectClassKey = _iSubjectClassKey;

            this.m_bCanChange = false;
            //getInfoFinal();
            GetAllInfo(_iSubjectClassKey);
            CheckScoreTypeLock(GetSubjectClassKey(), m_lScoreType);
            this.m_bCanChange = true;
        }
        public FrmScore_Input(int _iSubjectClassKey, eFuncTions _eType)
        {
            if (!SysUtils.CheckAccessByRule(RuleConfig.SCORETRANSCRIPTS))
            {
                XtraMessageBox.Show("Bạn không có quyền này!", "Thông báo");
                return;
            }
            //UniMana.Lib.Sys.Utils.SetRuleToXucBar(xucBar1, RuleConfig.SCORETRANSCRIPTS);
            InitializeComponent();
            InitControlEvent();
            m_iSubjectClassKey = _iSubjectClassKey;
            labelSubjectClassKey.Text = _iSubjectClassKey.ToString();
            #region [Input Score]
            if (_eType == eFuncTions.Input)
            {
                xucBar1.Enabled = true;
                this.m_bCanChange = false;
                menuRequiredEditScore.Enabled = true;
                GetAllInfo(_iSubjectClassKey);
                CheckScoreTypeLock(GetSubjectClassKey(), m_lScoreType);
                this.m_bCanChange = true;
                m_eType = eFuncTions.Input;
            }
            #endregion
            #region [Check Score]
            else if (_eType == eFuncTions.Check)
            {
                m_eType = eFuncTions.Check;
                menuRequiredEditScore.Enabled = true;
                btnChecked.Visible = true;
                GetAllInfo(_iSubjectClassKey);
                CheckScoreTypeFinishInput(GetSubjectClassKey(), m_lScoreType);
                GetNamePercentScore(m_iSubjectClassKey);

                xucBar1.btnAddNew.Enabled = false;
                xucBar1.btnCancel.Enabled = false;
                xucBar1.btnDelete.Enabled = false;
                xucBar1.btnEdit.Enabled = false;
                xucBar1.btnExportExcel.Enabled = false;
                xucBar1.btnImportExcel.Enabled = false;
                xucBar1.btnPrint.Enabled = false;
                xucBar1.btnSave.Enabled = false;
                xucBar1.btnEdit.Enabled = false;
                xucBar1.btnCancel.Enabled = false;
                xucBar1.btnRefresh.Enabled = true;
            }
            #endregion

            #region [SubjectClass Option]
            else
            {
                m_eType = eFuncTions.View;
                menuRequiredEditScore.Enabled = true;
                
                //xucBar1.Enabled = false;
                xucBar1.btnRefresh.Visibility = BarItemVisibility.Never;
                xucBar1.btnEdit.Visibility = BarItemVisibility.Never;
                xucBar1.btnImportExcel.Visibility = BarItemVisibility.Never;
                //xucBar1.btnExportExcel.Visibility = BarItemVisibility.Never;
                xucBar1.btnPrint.Enabled = true;
                xucBar1.btnExportExcel.Enabled = true;
                
                btnChecked.Visible = false;
                btnLockAll.Visible = false;
                GetAllInfo(_iSubjectClassKey);
                GetNamePercentScore(m_iSubjectClassKey);
            }
            #endregion

            #region [Start Thread]
            m_tThread = new Thread(new ThreadStart(SaveScore));
            m_tThread.IsBackground = true;
            m_tThread.Start();
            #endregion
        }
        #endregion 

        #region[Events]
        #region [Buttons]
        public void InitControlEvent()
        {
            //xucBar1.btnAddNew_Click += new UniMana.Controls.xucBar.ButtonClickHandler(this.btnAddNew_Click);
            xucBar1.btnSave_Click += new Utils.Controls.xucBar.ButtonClickHandler(this.btnSave_ItemClick);
            xucBar1.btnRefresh_Click += new Utils.Controls.xucBar.ButtonClickHandler(this.btnRefresh_ItemClick);
            xucBar1.btnExport_Click += new Utils.Controls.xucBar.ButtonClickHandler(this.btnExportExcel_ItemClick);
            xucBar1.btnPrint_Click += new Utils.Controls.xucBar.ButtonClickHandler(this.btnPrint_ItemClick);
            xucBar1.btnEdit_Click += new Utils.Controls.xucBar.ButtonClickHandler(this.btnEdit_Click);
            xucBar1.btnCancel_Click += new Utils.Controls.xucBar.ButtonClickHandler(btnCancel_Click);
            xucBar1.btnImport_Click += new Utils.Controls.xucBar.ButtonClickHandler(btnImportExcel_ItemClick);
            //xucBar1.btnDelete_Click += new Controls.xucBar.ButtonClickHandler(btnDelete_ItemClick);
        }
        private void btnSave_ItemClick(object sender, ItemClickEventArgs e)
        {
            grvScore.ClearColumnsFilter();
            #region [Lưu điểm]
            DialogResult diag = XtraMessageBox.Show("Bạn có muốn lưu thay đổi?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
            switch (diag)
            {
                #region [Yes]
                case DialogResult.Yes:
                    {
                            int sClassKey = GetSubjectClassKey();
                            if (grvScore.RowCount > 0 && grvScore.Columns.Count > 5)
                            {
                                for (int i = 0; i < grvScore.RowCount; i++)
                                {
                                    for (int j = 0; j < m_lScoreType.Count; j++)
                                    {
                                        int column = m_dtInfoStudent.Columns.Count + j * 3;
                                        if (m_data.m_DCReadOnly.Training_Scores.CheckScores(Guid.Parse(grvScore.GetRowCellValue(i, grvScore.Columns["SVKey"]).ToString()), sClassKey, int.Parse(m_lScoreType[j].ToString())) == false)
                                        {
                                            if (grvScore.GetRowCellValue(i, grvScore.Columns[column]) == null || grvScore.GetRowCellValue(i, grvScore.Columns[column]).ToString() == "")
                                            {
                                                Training_ScoreInfo info = new Training_ScoreInfo(
                                                                                            grvScore.GetRowCellValue(i, grvScore.Columns["SVKey"]).ToString(),
                                                                                            GetSubjectClassKey(),
                                                                                            int.Parse(m_lScoreType[j].ToString()));
                                                info.Properties.Training_StudentKey = Guid.Parse(grvScore.GetRowCellValue(i, grvScore.Columns["SVKey"]).ToString());
                                                info.Properties.Training_Subject_ClassKey = sClassKey; 
                                                info.Properties.Training_ScoreTypeKey = int.Parse(m_lScoreType[j].ToString());
                                                info.Properties.OnlyRead = bool.Parse(grvScore.GetRowCellValue(i, grvScore.Columns[column + 2]).ToString());
                                                info.Properties.Training_StudentID = grvScore.GetRowCellValue(i, grvScore.Columns["MSSV"]).ToString();
                                                info.Properties.Note = grvScore.GetRowCellValue(i, grvScore.Columns["Ghi chú"]).ToString();
                                                info.Save();
                                            }
                                            else
                                            {

                                                Training_ScoreInfo info = new Training_ScoreInfo(
                                                                                            grvScore.GetRowCellValue(i, grvScore.Columns["SVKey"]).ToString(),
                                                                                            GetSubjectClassKey(),
                                                                                            int.Parse(m_lScoreType[j].ToString()));
                                                info.Properties.Training_StudentKey = Guid.Parse(grvScore.GetRowCellValue(i, grvScore.Columns["SVKey"]).ToString());
                                                info.Properties.Training_Subject_ClassKey = sClassKey;
                                                info.Properties.Training_ScoreTypeKey = int.Parse(m_lScoreType[j].ToString());
                                                info.Properties.Score = Convert.ToDouble(grvScore.GetRowCellValue(i, grvScore.Columns[column]).ToString());
                                                info.Properties.OnlyRead = bool.Parse(grvScore.GetRowCellValue(i, grvScore.Columns[column + 2]).ToString());
                                                info.Properties.Training_StudentID = grvScore.GetRowCellValue(i, grvScore.Columns["MSSV"]).ToString();
                                                info.Properties.Note = grvScore.GetRowCellValue(i, grvScore.Columns["Ghi chú"]).ToString();
                                                info.Save();
                                            }
                                        }
                                        else
                                        {
                                            if (grvScore.GetRowCellValue(i, grvScore.Columns[column]) == null || grvScore.GetRowCellValue(i, grvScore.Columns[column]).ToString() == "")
                                            {
                                               Training_ScoreInfo info = new Training_ScoreInfo(grvScore.GetRowCellValue(i, grvScore.Columns["SVKey"]).ToString(),
                                                                                                sClassKey,
                                                                                                int.Parse(m_lScoreType[j].ToString()));
                                                info.Properties.Score = null;
                                                info.Properties.OnlyRead = bool.Parse(grvScore.GetRowCellValue(i, grvScore.Columns[column + 2]).ToString());
                                                info.Properties.Training_StudentID = grvScore.GetRowCellValue(i, grvScore.Columns["MSSV"]).ToString();
                                                info.Properties.Note = grvScore.GetRowCellValue(i, grvScore.Columns["Ghi chú"]).ToString();
                                                info.Save();
                                            }
                                            else
                                            {
                                                Training_ScoreInfo info = new Training_ScoreInfo(grvScore.GetRowCellValue(i, grvScore.Columns["SVKey"]).ToString(),
                                                                                                sClassKey,
                                                                                                int.Parse(m_lScoreType[j].ToString()));
                                                info.Properties.Score = Convert.ToDouble(grvScore.GetRowCellValue(i, grvScore.Columns[column]).ToString());
                                                info.Properties.OnlyRead = bool.Parse(grvScore.GetRowCellValue(i, grvScore.Columns[column + 2]).ToString());
                                                info.Properties.Training_StudentID = grvScore.GetRowCellValue(i, grvScore.Columns["MSSV"]).ToString();
                                                info.Properties.Note = grvScore.GetRowCellValue(i, grvScore.Columns["Ghi chú"]).ToString();
                                                info.Save();
                                            }
                                        }
                                    }
                                    //Luu diem hoc phan
                                    if (m_iPosition == m_lScoreType.Count-1)
                                    {
                                        string studentKey = grvScore.GetRowCellValue(i, grvScore.Columns["SVKey"]).ToString();
                                        Training_Student_Subject_ClassInfo infoStudentClass = new Training_Student_Subject_ClassInfo(studentKey, sClassKey);
                                        if (grvScore.GetRowCellValue(i, grvScore.Columns["Học phần"]) != null)
                                        {
                                            if (grvScore.GetRowCellValue(i, grvScore.Columns["Học phần"]).ToString() != "")
                                            {
                                                infoStudentClass.Properties.AverageScore = Convert.ToDouble(grvScore.GetRowCellValue(i, grvScore.Columns["Học phần"]).ToString());
                                                infoStudentClass.Properties.Training_StudentKey = Guid.Parse(studentKey);
                                                infoStudentClass.Properties.Training_Subject_ClassKey = sClassKey;
                                                infoStudentClass.Properties.AverageScoreFinal = Convert.ToDouble(grvScore.GetRowCellValue(i, grvScore.Columns["Học phần"]).ToString());
                                                infoStudentClass.Save();
                                            }
                                        }
                                    }
                                }
                                if (m_iPosition == m_lScoreType.Count - 1)
                                {
                                    DataTable _dtListScore = new DataTable();
                                    _dtListScore = m_data.m_DCReadOnly.Training_Scores.GetSubjectScoreListofStudentBySubjectClass(
                                                                        m_data.m_DCReadOnly.Training_Subjects,
                                                                        m_data.m_DCReadOnly.Training_TrainingProgram_Details,
                                                                        m_data.m_DCReadOnly.Training_Student_Subject_Classes,
                                                                        m_data.m_DCReadOnly.Training_Subject_Classes,
                                                                        m_data.m_DCReadOnly.Training_Students,
                                                                        m_data.m_DCReadOnly.Training_Student_Classes,
                                                                        m_data.m_DCReadOnly.Catalogue_Terms,
                                                                        m_data.m_DCReadOnly.Catalogue_SchoolYears,
                                                                        GetSubjectClassKey()).ToDataTable();
                                    CaculateAverageScoreAccumulates(_dtListScore, m_dtInfoStudent);
                                }
                                XtraMessageBox.Show("Lưu thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            }
                        break;
                    }
                #endregion
                #region [No]
                case DialogResult.No:
                    {
                        break;
                    }
                #endregion
            }
            #region [btn-grv]
            this.m_bCanEdit = false;
            btnLockAll.Visible = false;
            //btnLockAll.Enabled = false;
            xucBar1.btnSave.Enabled = false;
            xucBar1.btnCancel.Enabled = false;
            xucBar1.btnImportExcel.Enabled = false;
            xucBar1.btnEdit.Enabled = true;
            #endregion
            #endregion
            //panelControl5.Visible = true;
            this.splitContainerControl1.Collapsed = false;
            labelSubjectClassID.Text = "";
        }
        private void btnRefresh_ItemClick(object sender, ItemClickEventArgs e)
        {
            #region 
            //getSubjectClass();
            //LoadData();
            //lueCatalogue_SchoolYear.EditValue = null;
            //lueCatalogue_Term.EditValue = null;
            //gctSubjectClass.DataSource = null;
            //btnLockAll.Enabled = false;

            //txtCredits.Text = null;
            //txtDegree.Text = null;
            //txtDepartment.Text = null;
            //txtIDSubject.Text = null;
            //txtLevel.Text = null;
            //txtName.Text = null;
            ////txtNote.Text = null;
            //txtSubjectName.Text = null;
            //gctScore.DataSource = null;
            //grvScore.Columns.Clear();

            ////panelControl5.Visible = true;
            //this.splitContainerControl1.Collapsed = false;
            //labelSubjectClassID.Text = "";

            //txtSubjectClassID.Text = null;
            //txtSubjectClassID.Focus();
            #endregion
            int sClassKey = GetSubjectClassKey();
            this.m_bCanEdit = false;
            this.m_bCanChange = false;
            this.grvScore.BeginUpdate();
            //output Score
            OutputScore(sClassKey);
            this.grvScore.EndUpdate();

            btnLockAll.Visible = false;
            //btnLockAll.Enabled = false;
            xucBar1.btnSave.Enabled = false;
            xucBar1.btnCancel.Enabled = false;
            xucBar1.btnImportExcel.Enabled = false;
            xucBar1.btnEdit.Enabled = true;

            //panelControl5.Visible = true;
            this.splitContainerControl1.Collapsed = false;
            labelSubjectClassID.Text = "";
            lbcTimeInputScore.Text = "";
            //
            CheckScoreTypeLock(GetSubjectClassKey(), m_lScoreType);
            CheckScoreTypeFinishInput(GetSubjectClassKey(), m_lScoreType);

            //Show scoreletter and score subject
            int _iColumnEdit = m_dtInfoStudent.Columns.Count + m_iPosition * 3;
            for (int i = 0; i < grvScore.RowCount; i++)
            {
                if (grvScore.GetRowCellValue(i, grvScore.Columns[_iColumnEdit]) != null &&
                    grvScore.GetRowCellValue(i, grvScore.Columns[_iColumnEdit]).ToString() != "")
                {
                    string s = m_cReadnumber.Convert(grvScore.GetRowCellValue(i, grvScore.Columns[_iColumnEdit]).ToString(), '.', " chấm ");
                    this.grvScore.SetRowCellValue(i, grvScore.Columns[_iColumnEdit + 1], UppercaseFirst(s));
                }
                else
                {
                    this.grvScore.SetRowCellValue(i, grvScore.Columns[_iColumnEdit + 1], "");
                }
            }
            //Convert scale 4 and scoreletter for University and Colleges
            if (CheckLevel(GetSubjectClassKey()) != (int)DefaultConfig.Catalogue_Level.Intermediate)
            {
                for (int i = 0; i < grvScore.RowCount; i++)
                {
                    if (grvScore.GetRowCellValue(i, grvScore.Columns["Điểm kết thúc môn"]) != null) //Học phần
                    {
                        if (grvScore.GetRowCellValue(i, grvScore.Columns["Điểm kết thúc môn"]).ToString() != "")
                        {
                            try
                            {
                                double score = Convert.ToDouble(grvScore.GetRowCellValue(i, grvScore.Columns["Điểm kết thúc môn"]).ToString());
                                grvScore.SetRowCellValue(i, grvScore.Columns["Thang điểm 4"], ChangeScoreNumber(score).ToString());
                                grvScore.SetRowCellValue(i, grvScore.Columns["Điểm chữ"], ChangeScoreLetter(score));
                            }
                            catch { }
                        }
                    }
                }
            }

        }
        private void btnExportExcel_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (!SysUtils.CheckExportByRule(RuleConfig.SCORETRANSCRIPTS))
            {
                XtraMessageBox.Show("Bạn không có quyền này!","Thông báo");
                return;
            }
            if (grvScore.RowCount > 0)
            {
                int subjectClassKey = GetSubjectClassKey();
                Training_Subject_ClassInfo info = new Training_Subject_ClassInfo(subjectClassKey);
                SaveFileDialog saveFile = new SaveFileDialog();
                saveFile.FileName = "Bảng Điểm Lớp_" + info.Properties.ID.ToString() + "_" + DateTime.Now.Date.ToShortDateString().Replace('/', '_');
                saveFile.Title = "Xuất ra tệp tin";
                saveFile.DefaultExt = "xls";
                saveFile.Filter = "Excel 2003 (*.xls)|";
                if (saveFile.ShowDialog() == DialogResult.OK)
                {
                    grvScore.ExportToXls(saveFile.FileName);
                }
            }
        }
        private void btnImportExcel_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (!SysUtils.CheckImportByRule(RuleConfig.SCORETRANSCRIPTS))
            {
                XtraMessageBox.Show("Bạn không có quyền này","Thông báo");
                return;
            }
            if (grvScore.Columns.Count > 6)
            {
                try
                {
                    #region [Load data]
                    this.m_bCanChange = true;
                    this.xucBar1.dlg.Close();
                    OpenFileDialog openFile_ = new OpenFileDialog();
                    openFile_.Title = "Open File Excel";
                    openFile_.DefaultExt = "xls";
                    openFile_.Filter = "Excel Files |*.xlsx;*.xls";
                    if (openFile_.ShowDialog() == DialogResult.OK)
                    {
                        OleDbConnection connection_ = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + openFile_.FileName + ";Extended Properties=\"Excel 8.0;HDR=No;\"");
                        connection_.Open();
                        DataTable dtExcelSheet = new DataTable();
                        dtExcelSheet = connection_.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
                        SubFrmChooseExcelSheet chooseExcelSheet = new SubFrmChooseExcelSheet();
                        chooseExcelSheet.m_dtInfo = m_dtInfoStudent;
                        chooseExcelSheet.m_iSubjectClassKey = GetSubjectClassKey();
                        chooseExcelSheet.m_lScoreType = m_lScoreType;
                        chooseExcelSheet.m_gPersonelKey = Guid.Parse(UniMana.Utils.LoginInfo.GblLoginInfo.sysLoginPersionalKey.ToString());
                        chooseExcelSheet.m_iPosition = m_dtInfoStudent.Columns.Count + m_iPosition * 3;
                        chooseExcelSheet.SetDataSource(dtExcelSheet);
                        chooseExcelSheet.SetChooseSheet();
                        chooseExcelSheet.ShowDialog();
                        if (!chooseExcelSheet.Ok)
                        {
                            connection_.Close();
                            return;
                        }
                        string sheet = chooseExcelSheet.LookupEditText;
                        OleDbDataAdapter oleDbDataAdapter = new OleDbDataAdapter("SELECT * FROM [" + sheet + "]", connection_);
                        DataTable dt = new DataTable();
                        oleDbDataAdapter.Fill(dt);
                        connection_.Close();
                        chooseExcelSheet.SetDatabaseColumns(this.m_dtScore);
                        chooseExcelSheet.SetRluColumns(dt);
                        chooseExcelSheet.SetChooseData();
                        chooseExcelSheet.ShowDialog();
                        if (!chooseExcelSheet.Import)
                        {
                            return;
                        }
                        xucBar1.dlg = new DevExpress.Utils.WaitDialogForm();
                        for (int i = 1; i < dt.Rows.Count; i++)
                        {
                            if (dt.Rows[i][0] != null)
                            {
                                if (dt.Rows[i][0].ToString() != "")
                                {
                                    for (int k = 0; k < grvScore.RowCount; k++)
                                    {
                                        if (dt.Rows[i][0].ToString() == grvScore.GetRowCellValue(k, grvScore.Columns[1]).ToString())
                                        {
                                            for (int j = 0; j < dt.Columns.Count; j++)
                                            {
                                                if (chooseExcelSheet.GetDBColumns(j) != -1)
                                                {
                                                    if (dt.Rows[i][j].ToString() != null)
                                                    {
                                                        if (dt.Rows[i][j].ToString() != "")
                                                        {
                                                            double score;
                                                            bool check = double.TryParse(dt.Rows[i][j].ToString(), out score);
                                                            if (check)
                                                            {
                                                                if (score >= 0 && score <= 10)
                                                                {
                                                                    if (score.ToString().Length <= 4)
                                                                    {
                                                                        grvScore.SetRowCellValue(k, grvScore.Columns[chooseExcelSheet.GetDBColumns(j)], score);
                                                                    }
                                                                    else
                                                                    {
                                                                        grvScore.SetRowCellValue(k, grvScore.Columns[chooseExcelSheet.GetDBColumns(j)], Math.Round(score, 2));
                                                                    }
                                                                }
                                                            }
                                                            else { }
                                                        }
                                                        else
                                                        {
                                                            //grvScore.SetRowCellValue(k, grvScore.Columns[chooseExcelSheet.GetDBColumns(j)], 0);
                                                        }
                                                    }
                                                    else
                                                    {
                                                        //grvScore.SetRowCellValue(k, grvScore.Columns[chooseExcelSheet.GetDBColumns(j)], 0);
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    //XtraMessageBox.Show("If 3");
                                }
                            }
                            else
                            {
                                //XtraMessageBox.Show("If 2");
                            }
                        }
                        xucBar1.dlg.Close();
                        //
                        xucBar1.btnSave.Enabled = true;
                        xucBar1.btnCancel.Enabled = true;
                        //xucBar1.btnImportExcel.Enabled = false;
                        xucBar1.btnEdit.Enabled = false;
                        #region [Save Score]
                        grvScore.ClearColumnsFilter();
                        int sClassKey = GetSubjectClassKey();
                        if (grvScore.RowCount > 0 && grvScore.Columns.Count > 5)
                        {
                            for (int i = 0; i < grvScore.RowCount; i++)
                            {
                                for (int j = 0; j < m_lScoreType.Count; j++)
                                {
                                    int column = m_dtInfoStudent.Columns.Count + j * 3;
                                    if (m_data.m_DCReadOnly.Training_Scores.CheckScores(Guid.Parse(grvScore.GetRowCellValue(i, grvScore.Columns["SVKey"]).ToString()), sClassKey, int.Parse(m_lScoreType[j].ToString())) == false)
                                    {
                                        if (grvScore.GetRowCellValue(i, grvScore.Columns[column]) == null || grvScore.GetRowCellValue(i, grvScore.Columns[column]).ToString() == "")
                                        {
                                            Training_ScoreInfo info = new Training_ScoreInfo(
                                                                                        grvScore.GetRowCellValue(i, grvScore.Columns["SVKey"]).ToString(),
                                                                                        GetSubjectClassKey(),
                                                                                        int.Parse(m_lScoreType[j].ToString()));
                                            info.Properties.Training_StudentKey = Guid.Parse(grvScore.GetRowCellValue(i, grvScore.Columns["SVKey"]).ToString());
                                            info.Properties.Training_Subject_ClassKey = sClassKey;
                                            info.Properties.Training_ScoreTypeKey = int.Parse(m_lScoreType[j].ToString());
                                            info.Properties.OnlyRead = bool.Parse(grvScore.GetRowCellValue(i, grvScore.Columns[column + 2]).ToString());
                                            info.Properties.Training_StudentID = grvScore.GetRowCellValue(i, grvScore.Columns["MSSV"]).ToString();
                                            info.Properties.Note = grvScore.GetRowCellValue(i, grvScore.Columns["Ghi chú"]).ToString();
                                            info.Save();
                                        }
                                        else
                                        {

                                            Training_ScoreInfo info = new Training_ScoreInfo(
                                                                                        grvScore.GetRowCellValue(i, grvScore.Columns["SVKey"]).ToString(),
                                                                                        GetSubjectClassKey(),
                                                                                        int.Parse(m_lScoreType[j].ToString()));
                                            info.Properties.Training_StudentKey = Guid.Parse(grvScore.GetRowCellValue(i, grvScore.Columns["SVKey"]).ToString());
                                            info.Properties.Training_Subject_ClassKey = sClassKey;
                                            info.Properties.Training_ScoreTypeKey = int.Parse(m_lScoreType[j].ToString());
                                            info.Properties.Score = Convert.ToDouble(grvScore.GetRowCellValue(i, grvScore.Columns[column]).ToString());
                                            info.Properties.OnlyRead = bool.Parse(grvScore.GetRowCellValue(i, grvScore.Columns[column + 2]).ToString());
                                            info.Properties.Training_StudentID = grvScore.GetRowCellValue(i, grvScore.Columns["MSSV"]).ToString();
                                            info.Properties.Note = grvScore.GetRowCellValue(i, grvScore.Columns["Ghi chú"]).ToString();
                                            info.Save();
                                        }
                                    }
                                    else
                                    {
                                        if (grvScore.GetRowCellValue(i, grvScore.Columns[column]) == null || grvScore.GetRowCellValue(i, grvScore.Columns[column]).ToString() == "")
                                        {
                                            Training_ScoreInfo info = new Training_ScoreInfo(grvScore.GetRowCellValue(i, grvScore.Columns["SVKey"]).ToString(),
                                                                                             sClassKey,
                                                                                             int.Parse(m_lScoreType[j].ToString()));
                                            info.Properties.Score = null;
                                            info.Properties.OnlyRead = bool.Parse(grvScore.GetRowCellValue(i, grvScore.Columns[column + 2]).ToString());
                                            info.Properties.Training_StudentID = grvScore.GetRowCellValue(i, grvScore.Columns["MSSV"]).ToString();
                                            info.Properties.Note = grvScore.GetRowCellValue(i, grvScore.Columns["Ghi chú"]).ToString();
                                            info.Save();
                                        }
                                        else
                                        {
                                            Training_ScoreInfo info = new Training_ScoreInfo(grvScore.GetRowCellValue(i, grvScore.Columns["SVKey"]).ToString(),
                                                                                            sClassKey,
                                                                                            int.Parse(m_lScoreType[j].ToString()));
                                            info.Properties.Score = Convert.ToDouble(grvScore.GetRowCellValue(i, grvScore.Columns[column]).ToString());
                                            info.Properties.OnlyRead = bool.Parse(grvScore.GetRowCellValue(i, grvScore.Columns[column + 2]).ToString());
                                            info.Properties.Training_StudentID = grvScore.GetRowCellValue(i, grvScore.Columns["MSSV"]).ToString();
                                            info.Properties.Note = grvScore.GetRowCellValue(i, grvScore.Columns["Ghi chú"]).ToString();
                                            info.Save();
                                        }
                                    }
                                }
                                //Luu diem hoc phan
                                if (m_iPosition == m_lScoreType.Count - 1)
                                {
                                    string studentKey = grvScore.GetRowCellValue(i, grvScore.Columns["SVKey"]).ToString();
                                    Training_Student_Subject_ClassInfo infoStudentClass = new Training_Student_Subject_ClassInfo(studentKey, sClassKey);
                                    if (grvScore.GetRowCellValue(i, grvScore.Columns["Học phần"]) != null)
                                    {
                                        if (grvScore.GetRowCellValue(i, grvScore.Columns["Học phần"]).ToString() != "")
                                        {
                                            infoStudentClass.Properties.AverageScore = Convert.ToDouble(grvScore.GetRowCellValue(i, grvScore.Columns["Học phần"]).ToString());
                                            infoStudentClass.Properties.Training_StudentKey = Guid.Parse(studentKey);
                                            infoStudentClass.Properties.Training_Subject_ClassKey = sClassKey;
                                            infoStudentClass.Properties.AverageScoreFinal = Convert.ToDouble(grvScore.GetRowCellValue(i, grvScore.Columns["Học phần"]).ToString());
                                            infoStudentClass.Save();
                                        }
                                    }
                                }
                            }
                            if (m_iPosition == m_lScoreType.Count - 1)
                            {
                                DataTable _dtListScore = new DataTable();
                                _dtListScore = m_data.m_DCReadOnly.Training_Scores.GetSubjectScoreListofStudentBySubjectClass(
                                                                    m_data.m_DCReadOnly.Training_Subjects,
                                                                    m_data.m_DCReadOnly.Training_TrainingProgram_Details,
                                                                    m_data.m_DCReadOnly.Training_Student_Subject_Classes,
                                                                    m_data.m_DCReadOnly.Training_Subject_Classes,
                                                                    m_data.m_DCReadOnly.Training_Students,
                                                                    m_data.m_DCReadOnly.Training_Student_Classes,
                                                                    m_data.m_DCReadOnly.Catalogue_Terms,
                                                                    m_data.m_DCReadOnly.Catalogue_SchoolYears,
                                                                    GetSubjectClassKey()).ToDataTable();
                                CaculateAverageScoreAccumulates(_dtListScore, m_dtInfoStudent);
                            }
                            XtraMessageBox.Show("Nhập điểm hoàn tất!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                        #endregion
                    }
                    else
                    {
                        //XtraMessageBox.Show("Do not open file!");
                    }
                    #endregion
                }
                catch 
                { 
                    //XtraMessageBox.Show("File nhập không đúng định dạng!","Thông báo");
                }
            }
            else
            {
                XtraMessageBox.Show("Lớp học phần chưa có cột điểm!", "Thông báo");
            }
        }
        private void btnPrint_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (CheckLevel(GetSubjectClassKey()) != (int)DefaultConfig.Catalogue_Level.Intermediate)
            {
                Training_Subject_ClassInfo info = new Training_Subject_ClassInfo(GetSubjectClassKey());
                if (grvScore.RowCount > 0)
                {
                    FrmScore_SubTransScripts f = new FrmScore_SubTransScripts(info.Properties.ID.ToString(), m_dtInfoStudent, true, txtCredits.Text);
                }
                else
                {
                    //XtraMessageBox.Show("Lớp học phần không tồn tại!\n Vui lòng chọn lớp học phần khác!","Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            else
            {
                RprScore_TranscriptsTC rpt = new RprScore_TranscriptsTC(GetSubjectClassKey(), m_lScoreType);
                rpt.ShowPreview();
            }
        }
        private void btnDelete_ItemClick(object sender, ItemClickEventArgs e)
        {
            //Set cot diem chuyen thang diem 4 & diem chu
            //for (int i = 0; i < grvScore.RowCount; i++)
            //{
            //    //if (!m_bCanChange)
            //    //{
            //    if (grvScore.GetRowCellValue(i, grvScore.Columns["Học phần"]) != null
            //    &&  grvScore.GetRowCellValue(i, grvScore.Columns["Học phần"]).ToString() != "")
            //    {
            //        if (grvScore.GetRowCellValue(i, grvScore.Columns["Học phần"]).ToString() != "")
            //        {
            //            double score = Convert.ToDouble(grvScore.GetRowCellValue(i, grvScore.Columns["Học phần"]).ToString());
            //            grvScore.SetRowCellValue(i, grvScore.Columns["Thang điểm 4"], ChangeScoreNumber(score).ToString());
            //            grvScore.SetRowCellValue(i, grvScore.Columns["Điểm chữ"], ChangeScoreLetter(score));
            //        }
            //    }
            //    //}
            //}
        }
        private void btnEdit_Click(object sender, ItemClickEventArgs e)
        {
            if (!SysUtils.CheckEditByRule(RuleConfig.SCORETRANSCRIPTS))
            {
                XtraMessageBox.Show("Bạn không có quyền này!","Thông báo");
                return;
            }
            if (grvScore.RowCount > 0)
            {
                this.m_bCanChange = true;
                btnLockAll.Visible = true;
                xucBar1.btnSave.Enabled = true;
                xucBar1.btnCancel.Enabled = true;
                xucBar1.btnImportExcel.Enabled = true;
                xucBar1.btnEdit.Enabled = false;
                this.m_bCanEdit = true;
                for (int i = 0; i < grvScore.Columns.Count; i++)
                {
                    if (i > 5)
                    {
                        if (CheckColumn(grvScore.Columns[i].Name) == 1)
                        {
                            grvScore.Columns[i].ColumnEdit = repositoryItemTextEdit1;
                            grvScore.Columns[i].OptionsColumn.AllowEdit = true;
                        }
                        else if (CheckColumn(grvScore.Columns[i].Name) == 2)
                        {
                            grvScore.Columns[i].OptionsColumn.AllowEdit = true;
                        }
                        else
                        {
                            grvScore.Columns[i].OptionsColumn.AllowEdit = false;                                
                        }
                    }
                    else
                    {
                        grvScore.Columns[i].OptionsColumn.AllowEdit = false;
                    }
                }
            //Lock 
            grvScore.Columns["Điểm kết thúc môn"].OptionsColumn.AllowEdit = false;
            grvScore.Columns["Điểm kết thúc môn"].ColumnEdit = repositoryItemTextEdit1;
            grvScore.Columns["Ghi chú"].OptionsColumn.AllowEdit = true;
            //panelControl5.Visible = false;
            this.splitContainerControl1.Collapsed =true;
            int _iSubjectClasssKey = GetSubjectClassKey();
            Guid personelKey = Guid.Parse(UniMana.Utils.LoginInfo.GblLoginInfo.sysLoginPersionalKey.ToString());
            for (int j = 0; j < m_lScoreType.Count; j++)
            {
                //xac dinh khoa cac cot diem
                Training_SubjectClass_ScoreTypeInfo infoSS = new Training_SubjectClass_ScoreTypeInfo(GetSubjectClassKey(), m_lScoreType[j]);
                Training_Score_TaskInputInfo infoTask = new Training_Score_TaskInputInfo(
                                                                m_gPersonelKey, _iSubjectClasssKey, SysDateTime.Now);
                int column = m_dtInfoStudent.Columns.Count + j * 3;
                if (m_lScoreType[j] == m_lScoreType[m_iPosition] &&
                    infoTask.Properties.Personnel_PersonnelKey == m_gPersonelKey && infoSS.Properties.Check != true)
                {
                    grvScore.Columns[column].OptionsColumn.AllowEdit = true;
                    grvScore.Columns[column + 2].OptionsColumn.AllowEdit = true;
                    try
                    {
                        DateTime date;
                        if (DateTime.TryParse(infoTask.Properties.Date.ToString(), out date))
                        {
                            DateTime _dtime = date.AddDays(Convert.ToDouble(infoTask.Properties.Period.ToString()));
                            lbcTimeInputScore.Text = "Thời hạn nhập điểm: " + _dtime.ToString("dd/MM/yyyy");
                        }
                    }
                    catch { }
                }
                else
                {
                    grvScore.Columns[column].OptionsColumn.AllowEdit = false;
                    grvScore.Columns[column + 2].OptionsColumn.AllowEdit = false;
                }
            }
            GetNamePercentScore(_iSubjectClasssKey);
            if (m_bFinishInput == true)
            {
                xucBar1.btnImportExcel.Enabled = false;
                xucBar1.btnSave.Enabled = false;
            }
            else
            {
                xucBar1.btnImportExcel.Enabled = true;
                xucBar1.btnSave.Enabled = true;
            }
                CheckScoreTypeLock(GetSubjectClassKey(), m_lScoreType);
            }
        }
        private void btnCancel_Click(object sender, ItemClickEventArgs e)
        {
            int sClassKey = GetSubjectClassKey();
            this.m_bCanEdit = false;
            this.m_bCanChange = false;
            this.grvScore.BeginUpdate();
            //output Score
            OutputScore(sClassKey);
            this.grvScore.EndUpdate();

            btnLockAll.Visible = false;
            //btnLockAll.Enabled = false;
            xucBar1.btnSave.Enabled = false;
            xucBar1.btnCancel.Enabled = false;
            xucBar1.btnImportExcel.Enabled = false;
            xucBar1.btnEdit.Enabled = true;

            //panelControl5.Visible = true;
            this.splitContainerControl1.Collapsed = false;
            labelSubjectClassID.Text = "";
            lbcTimeInputScore.Text = "";
        }
        private void btnLockAll_Click(object sender, EventArgs e)
        {
            grvScore.ClearColumnsFilter();
            if (grvScore.RowCount > 0)
            {
                int _iSubjectClassKey = GetSubjectClassKey();
                Training_ScoreTypeInfo infoScoreType = new Training_ScoreTypeInfo(m_iScoreTypeLock);
                DialogResult diag = XtraMessageBox.Show("Bạn có muốn khóa điểm " + infoScoreType.Properties.Name.ToString() + "?\nĐiểm " + infoScoreType.Properties.Name.ToString() + " sẽ không được chỉnh sửa sau khi khóa!", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                switch (diag)
                {
                    case DialogResult.Yes:
                        {
                            //Xac nhan khoa
                            Training_SubjectClass_ScoreTypeInfo infoSubjectClassScoreType = new Training_SubjectClass_ScoreTypeInfo(_iSubjectClassKey, m_iScoreTypeLock);
                            infoSubjectClassScoreType.Properties.Lock = true;
                            infoSubjectClassScoreType.Properties.LockPersonnel_PersonnelKey = UniMana.Utils.LoginInfo.GblLoginInfo.sysLoginPersionalKey;
                            infoSubjectClassScoreType.Save();
                            LockAll(m_iPosition);
                            try
                            {
                                for (int i = 0; i < grvScore.RowCount; i++)
                                {
                                    Training_ScoreInfo infoScore = new Training_ScoreInfo(grvScore.GetRowCellValue(i, grvScore.Columns["SVKey"]).ToString(),
                                                                                    _iSubjectClassKey,
                                                                                    m_iScoreTypeLock);
                                    infoScore.Properties.Training_StudentKey = Guid.Parse(grvScore.GetRowCellValue(i, grvScore.Columns["SVKey"]).ToString());
                                    infoScore.Properties.Training_ScoreTypeKey = m_iScoreTypeLock;
                                    infoScore.Properties.Training_Subject_ClassKey = GetSubjectClassKey();
                                    infoScore.Properties.OnlyRead = true;
                                    infoScore.Properties.Training_StudentID = grvScore.GetRowCellValue(i, grvScore.Columns["MSSV"]).ToString();
                                    infoScore.Properties.Note = grvScore.GetRowCellValue(i, grvScore.Columns["Ghi chú"]).ToString();
                                    #region
                                    //if (grvScore.GetRowCellValue(i, grvScore.Columns[k]) == null || grvScore.GetRowCellValue(i, grvScore.Columns[k]).ToString() == "")
                                    //{
                                    //    infoScore.Properties.Score = null;
                                    //}
                                    //else
                                    //{
                                    //    infoScore.Properties.Score = Convert.ToDouble(grvScore.GetRowCellValue(i, grvScore.Columns[k]).ToString());
                                    //}
                                    #endregion
                                    infoScore.Save();
                                }
                            }
                            catch
                            {
                                #region [old]
                                //for (int i = 0; i < grvScore.RowCount; i++)
                                //{
                                //    Training_ScoreInfo infoScore = new Training_ScoreInfo(grvScore.GetRowCellValue(i, grvScore.Columns["SVKey"]).ToString(),
                                //                                                    _iSubjectClassKey,
                                //                                                    m_iScoreTypeLock);
                                //    infoScore.Properties.OnlyRead = true;
                                //    infoScore.Properties.Training_StudentID = grvScore.GetRowCellValue(i, grvScore.Columns["MSSV"]).ToString();
                                //    infoScore.Properties.Note = grvScore.GetRowCellValue(i, grvScore.Columns["Ghi chú"]).ToString();
                                //    infoScore.Save();
                                //}
                                #endregion
                            }
                            CheckScoreTypeLock(_iSubjectClassKey, m_lScoreType);

                            if (m_bFinishInput == true)
                            {
                                xucBar1.btnImportExcel.Enabled = false;
                                xucBar1.btnSave.Enabled = false;
                            }
                            else
                            {
                                xucBar1.btnImportExcel.Enabled = true;
                                xucBar1.btnSave.Enabled = true;
                            }
                            //Xac dinh dong mo cac cot diem
                            Training_Score_TaskInputInfo infoTask = new Training_Score_TaskInputInfo(
                                                                                m_gPersonelKey, _iSubjectClassKey, SysDateTime.Now);
                            infoTask.Properties.Lock = true;
                            infoTask.Save();
                            for (int i = 0; i < m_lScoreType.Count; i++)
                            {
                                Training_SubjectClass_ScoreTypeInfo infoSS = new Training_SubjectClass_ScoreTypeInfo(GetSubjectClassKey(), m_lScoreType[i]);
                                int column = m_dtInfoStudent.Columns.Count + i * 3;
                                if (m_lScoreType[i] == m_lScoreType[m_iPosition] &&
                                    infoTask.Properties.Personnel_PersonnelKey == m_gPersonelKey && infoSS.Properties.Check != true
                                    && infoTask.Properties.Lock !=true)
                                {
                                    grvScore.Columns[column].OptionsColumn.AllowEdit = true;
                                    grvScore.Columns[column + 2].OptionsColumn.AllowEdit = true;
                                }
                                else
                                {
                                    grvScore.Columns[column].OptionsColumn.AllowEdit = false;
                                    grvScore.Columns[column + 2].OptionsColumn.AllowEdit = false;
                                }
                            }
                            //Lock all User division InputScore
                            //Training_Score_TaskInputsInfo infoScoreTaskInput = new Training_Score_TaskInputsInfo(GetSubjectClassKey());
                            //infoScoreTaskInput.Properties.Lock = true;
                            //infoScoreTaskInput.Save();

                            btnLockAll.Enabled = false;
                            XtraMessageBox.Show("Khóa hoàn tất!", "Thông báo");
                            break;
                        }
                    case DialogResult.No:
                        {
                            break;
                        }
                    default:
                        {
                            break;
                        }
                }
            }
        }
        private void btnChecked_Click(object sender, EventArgs e)
        {
            if (grvScore.RowCount > 0)
            {
                Training_SubjectClass_ScoreTypeInfo infoSS = new Training_SubjectClass_ScoreTypeInfo(GetSubjectClassKey(), m_iScoreTypeLock);
                if (infoSS.Properties.Lock == true)
                {
                    Training_ScoreTypeInfo infoScoreType = new Training_ScoreTypeInfo(m_iScoreTypeLock);
                    DialogResult diag = XtraMessageBox.Show("Bạn đã hoàn thành kiểm tra điểm " + infoScoreType.Properties.Name.ToString() + "?\n", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                    switch (diag)
                    {
                        case DialogResult.Yes:
                            {
                                //Xac nhan khoa
                                Training_SubjectClass_ScoreTypeInfo infoSubjectClassScoreType = new Training_SubjectClass_ScoreTypeInfo(GetSubjectClassKey(), m_iScoreTypeLock);
                                infoSubjectClassScoreType.Properties.Training_Subject_ClassKey = GetSubjectClassKey();
                                infoSubjectClassScoreType.Properties.Training_ScoreTypeKey = m_iScoreTypeLock;
                                infoSubjectClassScoreType.Properties.Check = true;
                                infoSubjectClassScoreType.Properties.CheckPersonnel_PersonnelKeyKey = m_gPersonelKey;
                                infoSubjectClassScoreType.Save();
                                //LockAll(m_iPosition);
                                CheckScoreTypeFinishInput(GetSubjectClassKey(), m_lScoreType);
                                //Xac nhan kiem tra mot cot diem
                                Training_Score_TaskInputInfo infoTask = new Training_Score_TaskInputInfo(
                                                                                m_gPersonelKey, GetSubjectClassKey(), SysDateTime.Now, false);
                                infoTask.Properties.Lock = true;
                                infoTask.Save();
                                btnChecked.Enabled = false;
                                //btnRequired.Enabled = false;
                                break;
                            }
                        case DialogResult.No:
                            {
                                break;
                            }
                        default:
                            {
                                break;
                            }
                    }
                }
                else
                {
                    Training_ScoreTypeInfo infoScoreType = new Training_ScoreTypeInfo(m_iScoreTypeLock);
                    XtraMessageBox.Show("Điểm " + infoScoreType.Properties.Name.ToString() + " chưa nhập xong!\nVui lòng kiểm tra lại!", "Thông báo");
                }
            }
        }
        #endregion
        #region [Form Event]
        private void FrmScore_Input_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (m_lRowScore != null)
            {
                if (m_lRowScore.Count > 0)
                {
                    XtraMessageBox.Show("Chương trình không thể đóng!\nĐang lưu dữ liệu!", "Thông báo");
                    e.Cancel = true;
                    //m_bIsClosed = false;
                }
                else
                {
                    //m_bIsClosed = true;
                }
            }
            else
            {
                //m_bIsClosed = true;
            }
        }
        private void FrmScore_Load(object sender, EventArgs e)
        {
            txtSubjectClassID.Focus();
        }
        private void FrmScore_Resize(object sender, EventArgs e)
        {
            int width = panelControl1.Width;
            labelSubjectClassID.Location = new System.Drawing.Point(width / 2 - labelSubjectClassID.Width / 2, labelSubjectClassID.Location.Y);
        }
        #endregion 
        #region [GridView Events]
        private void grvScore_CustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e)
        {
            int rowIndex = e.RowHandle;
            if (rowIndex >= 0)
            {
                rowIndex++;
                e.Info.DisplayText = rowIndex.ToString();
            }
        }
        private void grvScore_ShowingEditor(object sender, System.ComponentModel.CancelEventArgs e)
        {
            bool _bCanEdit = false;
            bool _bCantEdit = true;
            #region [Rang buoc nhap diem lan 2]
            if (CheckLevel(GetSubjectClassKey()) != (int)DefaultConfig.Catalogue_Level.Intermediate)
            {
                Training_SubjectClass_ScoreTypeInfo infoSS = new Training_SubjectClass_ScoreTypeInfo(GetSubjectClassKey(), DefaultConfig.SCORE_TYPE_3);
                if (infoSS.Properties.Training_Subject_ClassKey == GetSubjectClassKey())
                {
                    int pointsion = m_dtInfoStudent.Columns.Count + 6;
                    if (this.grvScore.FocusedColumn == this.grvScore.Columns[pointsion])
                    {
                        if (this.grvScore.GetFocusedRowCellValue(this.grvScore.Columns["Học phần"]) != null)
                        {
                            double score = this.grvScore.GetFocusedRowCellValue(this.grvScore.Columns["Học phần"]).ToDouble();
                            Training_Subject_ClassInfo sblInfo = new Training_Subject_ClassInfo(GetSubjectClassKey());
                            if (sblInfo.Properties.Yearly != null)
                            {
                                if (sblInfo.Properties.Yearly.Value)
                                {
                                    if (score >= DefaultConfig.MinScorePass_Yearly)
                                    {
                                        e.Cancel = true;
                                        return;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            #endregion
            if (this.m_bCanEdit)
            {
                //List<int> scoreType = m_Score.m_DCReadOnly.Training_SubjectClass_ScoreTypes.getListScoreTypeClass(m_Score.m_DCReadOnly.Training_ScoreTypes, lueTraining_Subject_Class.GetIntValue());
                List<string> scoreTypeChar = new List<string>();
                List<string> scoreTypeLock = new List<string>();
                for (int i = 0; i < m_lScoreType.Count; i++)
                {
                    var st = m_data.m_DCReadOnly.Training_ScoreTypes.Where(p => p.Training_ScoreTypeKey == int.Parse(m_lScoreType[i].ToString())).ToList();
                    scoreTypeChar.Add(st[0].Name.ToString() + "-Điểm số");
                    scoreTypeLock.Add(st[0].Name.ToString() + "-Khóa");
                }
                GridView grdView = (GridView)sender;
                for (int k = 0; k < scoreTypeLock.Count; k++)
                {
                    string colDS = ("col" + scoreTypeLock[k].ToString()).Replace(" ", "");
                    if (grvScore.FocusedColumn.Name == colDS)
                    {
                        if ((bool)grvScore.GetRowCellValue(grvScore.FocusedRowHandle, grvScore.Columns[scoreTypeLock[k].ToString()]))
                        {
                            e.Cancel = _bCantEdit;
                        }
                        else
                        {
                            e.Cancel = _bCanEdit;
                        }
                    }
                }
                for (int j = 0; j < scoreTypeChar.Count; j++)
                {
                    string colLock = ("col" + scoreTypeChar[j].ToString()).Replace(" ", "");
                    if (grvScore.FocusedColumn.Name == colLock)
                    {
                        try
                        {
                            if (!(bool)grvScore.GetRowCellValue(grvScore.FocusedRowHandle, grvScore.Columns[scoreTypeLock[j].ToString()]))
                            {
                                e.Cancel = _bCanEdit;
                            }
                            else
                            {
                                e.Cancel = _bCantEdit;
                            }
                        }
                        catch { }
                    }
                }
            }
            else
            {
                e.Cancel = _bCantEdit;
            }
        }
        private void grvSubjectClass_CustomDrawRowIndicator(object sender, RowIndicatorCustomDrawEventArgs e)
        {
            int rowIndex = e.RowHandle;
            if (rowIndex >= 0)
            {
                rowIndex++;
                e.Info.DisplayText = rowIndex.ToString();
            }
        }
        private void grvSubjectClass_DoubleClick(object sender, EventArgs e)
        {
            try
            {
                txtSubjectClassID.Text = grvSubjectClass.GetFocusedRowCellValue(grvSubjectClass.Columns["ID"]).ToString();
            }
            catch { }
        }
        private void grvScore_RowCellStyle(object sender, RowCellStyleEventArgs e)
        {
            if (m_eType == eFuncTions.Check || m_eType == eFuncTions.View)
            {
                if (grvScore.RowCount > 0 && grvScore.Columns.Count > 6)
                {
                    DataTable _dtScoreEdit = this.m_dtDraw;
                    if (_dtScoreEdit.Rows.Count > 0)
                    {
                        for (int l = 0; l < _dtScoreEdit.Rows.Count; l++)
                        {
                            for (int i = 0; i < grvScore.RowCount; i++)
                            {
                                if (_dtScoreEdit.Rows[l]["Training_StudentKey"].ToString() ==
                                    grvScore.GetRowCellValue(i, grvScore.Columns["SVKey"]).ToString())
                                {
                                    for (int j = 0; j < m_lScoreType.Count; j++)
                                    {
                                        if (Convert.ToInt32(_dtScoreEdit.Rows[l]["Training_ScoreTypeKey"].ToString())
                                            == m_lScoreType[j].ToInt())
                                        {
                                            int k = m_dtInfoStudent.Columns.Count + j * 3;
                                            if (e.Column == grvScore.Columns[k])
                                            {
                                                if (e.RowHandle == i)
                                                {
                                                    e.Appearance.BackColor = Color.Orange;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        private void grvScore_DoubleClick(object sender, EventArgs e)
        {
            try
            {
                int _iSubjectClassKey = GetSubjectClassKey();
                string _sStudentKey = grvScore.GetFocusedRowCellValue(grvScore.Columns["SVKey"]).ToString();
                if (m_data.m_DCReadOnly.Log_ScoreEdits.Check(_iSubjectClassKey, _sStudentKey) == true)
                {
                    FrmScore_ViewInfoEditScore f = new FrmScore_ViewInfoEditScore(_iSubjectClassKey, _sStudentKey);
                    f.ShowDialog();
                }
                else
                { }
            }
            catch { }
        }
        private void grvScore_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                this.grvScore.FocusedRowHandle += 1;
                this.grvScore.ShowEditor();
            }
        }
        private void grvScore_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e)
        {
            #region [Hien thi diem chu & tinh diem hoc phan]
            //if (m_dtScore.Columns.Count > 6)
            //{
            //    bool convert = false;
            //    int k = 0;
            //    for (int j = 0; j < m_lScoreType.Count; j++)
            //    {
            //        k = m_dtInfoStudent.Columns.Count + j * 3;
            //        if (grvScore.Columns[k] == e.Column)
            //        {
            //            convert = true;
            //            break;
            //        }
            //    }
            //    if (convert)
            //    {
            //        if(grvScore.GetRowCellValue(e.RowHandle, grvScore.Columns[k]) != null && grvScore.GetRowCellValue(e.RowHandle, grvScore.Columns[k]).ToString() !="")
            //        {
            //            string s = m_cReadnumber.Convert(e.Value.ToString(), '.', " chấm ");
            //            this.grvScore.SetRowCellValue(e.RowHandle, grvScore.Columns[k + 1], UppercaseFirst(s));
            //        }
            //        else
            //        {
            //            this.grvScore.SetRowCellValue(e.RowHandle, grvScore.Columns[k + 1], "");
            //        }
            //    }
            //}
            #endregion
            #region[Setvalue cot diem chuyen thang diem 4 & diem chu]
            //Dai hoc & cao dang
            //if (CheckLevel(GetSubjectClassKey()) != (int)DefaultConfig.Catalogue_Level.Intermediate)
            //{
            //    if (grvScore.Columns["Học phần"] == e.Column)
            //    {
            //        if (grvScore.GetRowCellValue(e.RowHandle, grvScore.Columns["Học phần"]) != null)
            //        {
            //            if (grvScore.GetRowCellValue(e.RowHandle, grvScore.Columns["Học phần"]).ToString() != "")
            //            {
            //                try
            //                {
            //                    double score = Convert.ToDouble(grvScore.GetRowCellValue(e.RowHandle, grvScore.Columns["Học phần"]).ToString());
            //                    grvScore.SetRowCellValue(e.RowHandle, grvScore.Columns["Thang điểm 4"], ChangeScoreNumber(score).ToString());
            //                    grvScore.SetRowCellValue(e.RowHandle, grvScore.Columns["Điểm chữ"], ChangeScoreLetter(score));
            //                }
            //                catch { }
            //            }
            //        }
            //    }
            //}
            //Trung cap
            #endregion
            #region [Caculate Subject Score]
            for (int i = 0; i < m_lScoreType.Count; i++)
            {
                int k = m_dtInfoStudent.Columns.Count + i * 3;
                if (e.Column.ColumnHandle == k)
                {
                    if (this.m_bCanChange)
                    {
                        //Tinh diem hoc phan Dai hoc & Cao dang
                        if (CheckLevel(GetSubjectClassKey()) != (int)DefaultConfig.Catalogue_Level.Intermediate)
                        {
                            CaculateFinalScore(GetSubjectClassKey(), e.RowHandle);
                        }
                        else//Tinh diem hoc phan Trung Cap
                        {
                            CaculateFinalScoreIntermediate(GetSubjectClassKey(), e.RowHandle);
                        }
                    }
                }
            }

            #endregion
            #region [Save each line]
            #region [Score]
            string _strStudentKey = grvScore.GetRowCellValue(e.RowHandle, grvScore.Columns["SVKey"]).ToString();
            int _iColumn = m_dtInfoStudent.Columns.Count + m_iPosition * 3;
            string _strScore = "";
            if (grvScore.GetRowCellValue(e.RowHandle, grvScore.Columns[_iColumn]) != null
                && grvScore.GetRowCellValue(e.RowHandle, grvScore.Columns[_iColumn]).ToString() != "")
            {
                _strScore = grvScore.GetRowCellValue(e.RowHandle, grvScore.Columns[_iColumn]).ToString();
            }
            else { }
            #endregion
            #region [Final ScoreType]
            if (m_iPosition == m_lScoreType.Count - 1)//Score Final
            {
                if (e.Column.VisibleIndex == _iColumn-1 ||
                    e.Column.FieldName == grvScore.Columns["Điểm kết thúc môn"].ToString())//Edit Column Score
                {
                    double _dAverageScore = 0;
                    //try
                    //{
                    #region [AverageScoreFinal Normal]
                    if (CheckLevel(GetSubjectClassKey()) != (int)DefaultConfig.Catalogue_Level.Intermediate)//University & Colleges
                    {
                        #region
                        for (int j = 0; j < m_lScoreType.Count; j++)
                        {
                            int k = m_dtInfoStudent.Columns.Count + j * 3;
                            if (grvScore.GetRowCellValue(e.RowHandle, grvScore.Columns[k]) != null)
                            {
                                if (grvScore.GetRowCellValue(e.RowHandle, grvScore.Columns[k]).ToString() != "")
                                {
                                    double score = double.Parse(grvScore.GetRowCellValue(e.RowHandle, grvScore.Columns[k]).ToString());
                                    _dAverageScore += score * m_lPpercent[j];
                                }
                            }
                        }
                        #endregion
                    }
                    else //Intermediate
                    {
                        #region 
                        double _dGK = 0;
                        int _iSumCoefficient = 0;
                        for (int j = 0; j < m_lScoreType.Count; j++)
                        {
                            int k = m_dtInfoStudent.Columns.Count + j * 3;
                            if (j != m_lScoreType.Count - 1)//tinh diem giua ki
                            {
                                _iSumCoefficient += m_lCoefficient[j];
                                if (grvScore.GetRowCellValue(e.RowHandle, grvScore.Columns[k]) != null &&
                                    grvScore.GetRowCellValue(e.RowHandle, grvScore.Columns[k]).ToString() != "")
                                {
                                    _dGK += Convert.ToDouble(grvScore.GetRowCellValue(e.RowHandle, grvScore.Columns[k]).ToString()) * m_lCoefficient[j];
                                }
                            }
                            else//Tinh diem hoc phan
                            {
                                if (grvScore.GetRowCellValue(e.RowHandle, grvScore.Columns[k]) != null &&
                                    grvScore.GetRowCellValue(e.RowHandle, grvScore.Columns[k]).ToString() != "")
                                {
                                    //double 
                                    _dAverageScore = Math.Round((Convert.ToDouble(grvScore.GetRowCellValue(e.RowHandle, grvScore.Columns[k]).ToString()) +
                                                Math.Round(_dGK / _iSumCoefficient, 0, MidpointRounding.AwayFromZero)) / 2, 1, MidpointRounding.AwayFromZero);
                                }
                                else
                                {
                                    _dAverageScore = Math.Round(_dGK / _iSumCoefficient, 0, MidpointRounding.AwayFromZero);
                                }
                            }
                        }
                        #endregion
                    }
                    #endregion

                    //Hữu ghi chú: Điểm miễn
                    #region [AverageScoreFinal Exemption]
                    if (e.Column.FieldName == grvScore.Columns["Điểm kết thúc môn"].ToString())  //Edit Column[FinalScore]
                    {
                        if (   grvScore.GetRowCellValue(e.RowHandle, grvScore.Columns["Điểm kết thúc môn"]).ToString() != "" 
                            && grvScore.GetRowCellValue(e.RowHandle, grvScore.Columns["Điểm kết thúc môn"]) != null)
                        {
                           
                            _dAverageScore = Convert.ToDouble(grvScore.GetRowCellValue(e.RowHandle, grvScore.Columns["Điểm kết thúc môn"]));
                            //MessageBox.Show(_dAverageScore+"");
                        }
                        else
                        {
                            _dAverageScore = 0;
                        }
                    }
                    #endregion

                    #region [Add List]
                    RowScore _rRowScore = new RowScore(Guid.Parse(_strStudentKey), GetSubjectClassKey(), 
                                                       m_lScoreType[m_iPosition].ToInt(),_strScore,
                                                       grvScore.GetRowCellValue(e.RowHandle, grvScore.Columns["Ghi chú"]).ToString(),
                                                       (bool)grvScore.GetRowCellValue(e.RowHandle, grvScore.Columns[_iColumn + 2]),
                                                       grvScore.GetRowCellValue(e.RowHandle, grvScore.Columns["MSSV"]).ToString(),
                                                       Math.Round(_dAverageScore, 1).ToString());
                    m_lRowScore.Add(_rRowScore);
                    #endregion
                    //}
                    //catch { }
                }

                #region [Edit Column[Locks] & Columnn[Note]]
                if (e.Column.VisibleIndex == _iColumn + 1 ||
                    e.Column.FieldName == grvScore.Columns["Ghi chú"].ToString())
                {
                    string _strNote = "";
                    if (grvScore.GetRowCellValue(e.RowHandle, grvScore.Columns["Ghi chú"]) != null &&
                        grvScore.GetRowCellValue(e.RowHandle, grvScore.Columns["Ghi chú"]).ToString() != "")
                    {
                        _strNote = grvScore.GetRowCellValue(e.RowHandle, grvScore.Columns["Ghi chú"]).ToString();
                    }
                    Training_ScoreInfo infoScore = new Training_ScoreInfo(_strStudentKey, GetSubjectClassKey(), m_lScoreType[m_iPosition].ToInt());
                    infoScore.Properties.Training_StudentKey = Guid.Parse(_strStudentKey);
                    infoScore.Properties.Training_Subject_ClassKey = GetSubjectClassKey();
                    infoScore.Properties.Training_ScoreTypeKey = m_lScoreType[m_iPosition].ToInt();
                    infoScore.Properties.OnlyRead = (bool)grvScore.GetRowCellValue(e.RowHandle, grvScore.Columns[_iColumn + 2]);
                    infoScore.Properties.Note = _strNote;
                    infoScore.Save();
                }
                #endregion
            }
            #endregion
            #region [Normal ScoreType]
            else
            {
                int _iColumnEdit = m_dtInfoStudent.Columns.Count + m_iPosition * 3 -1;
                if (e.Column.VisibleIndex == _iColumnEdit  || e.Column.VisibleIndex == _iColumnEdit+2 || e.Column.FieldName == grvScore.Columns["Ghi chú"].ToString())
                {
                    //Add list
                    string _strNote = "";
                    if (grvScore.GetRowCellValue(e.RowHandle, grvScore.Columns["Ghi chú"]) != null &&
                        grvScore.GetRowCellValue(e.RowHandle, grvScore.Columns["Ghi chú"]).ToString() != "")
                    {
                        _strNote = grvScore.GetRowCellValue(e.RowHandle, grvScore.Columns["Ghi chú"]).ToString();
                    }
                    RowScore _rRowScore = new RowScore(Guid.Parse(_strStudentKey), GetSubjectClassKey(), m_lScoreType[m_iPosition].ToInt(),
                                                            _strScore, _strNote,
                                                            (bool)grvScore.GetRowCellValue(e.RowHandle, grvScore.Columns[_iColumn + 2]),
                                                            grvScore.GetRowCellValue(e.RowHandle, grvScore.Columns["MSSV"]).ToString(), "");
                    m_lRowScore.Add(_rRowScore);
                }
            }
            #endregion
            #endregion
        }
        #endregion


        #region [Struct]
        private struct RowScore
        {
            public Guid _gStudentKey;//=Guid.Parse(DefaultConfig.EMPTY_GUID);
            public int _iSubjectClassKey;
            public int _iScoreTypeKey;
            public bool _bLock;
            public string _strStudentID;
            public string _dScore;
            public string _strNote;
            public string _dAverageScore;            
            public RowScore(Guid studentKey, int subjectClassKey, int scoreTypeKey, 
                string score, string note, bool bLock, string studentID, string averageScore)
            {
                _gStudentKey = studentKey;
                _iSubjectClassKey = subjectClassKey;
                _iScoreTypeKey = scoreTypeKey;
                _dScore = score;
                _strNote = note;
                _bLock = bLock;
                _strStudentID = studentID;
                _dAverageScore = averageScore;
            }
        }
        #endregion
        #region Methods
        /// <summary>
        /// Kiem tra dong tab
        /// </summary>
        //public bool IsClosed
        //{
        //    //get { return this.m_bIsClosed; }
        //}
        /// <summary>
        /// Lay ma lop hoc phan
        /// </summary>
        /// <returns></returns>
        private int GetSubjectClassKey()
        {
            return this.m_iSubjectClassKey;
        }
        /// <summary>
        /// Lay diem cua mot lop hoc phan
        /// </summary>
        /// <param name="subjectClassKey"></param>
        private void OutputScore(int subjectClassKey)
        {
            #region[Output Scores]
            #region [Student Info]
            m_dtScore = new DataTable();
            m_dtScore.Columns.Add("SVKey");
            m_dtScore.Columns.Add("MSSV");
            m_dtScore.Columns.Add("Họ lót");
            m_dtScore.Columns.Add("Tên");
            m_dtScore.Columns.Add("Ngày Sinh");
            m_dtScore.Columns.Add("Giới tính");
            for (int i = 0; i < m_dtInfoStudent.Rows.Count; i++)
            {
                DateTime date;
                if (DateTime.TryParse(m_dtInfoStudent.Rows[i]["Birthday"].ToString(), out date))
                {
                    m_dtScore.Rows.Add(new object[] { m_dtInfoStudent.Rows[i]["Training_StudentKey"].ToString(), m_dtInfoStudent.Rows[i]["ID"].ToString(), 
                                                    m_dtInfoStudent.Rows[i]["LastName"].ToString(), m_dtInfoStudent.Rows[i]["SureName"].ToString(), 
                                                date.ToString("dd/MM/yyyy"), m_dtInfoStudent.Rows[i]["Gender"].ToString()});
                }
                else
                {
                    try
                    {
                        m_dtScore.Rows.Add(new object[] { m_dtInfoStudent.Rows[i]["Training_StudentKey"].ToString(), m_dtInfoStudent.Rows[i]["ID"].ToString(), 
                                                    m_dtInfoStudent.Rows[i]["LastName"].ToString(), m_dtInfoStudent.Rows[i]["SureName"].ToString(), 
                                                    m_dtInfoStudent.Rows[i]["Birthday"].ToString(),m_dtInfoStudent.Rows[i]["Gender"].ToString()});
                    }
                    catch { }
                }
            }
            #endregion

            #region [Add Column ScoreType]
            for (int i = 0; i < m_lScoreType.Count; i++)
            {
                var st = m_data.m_DCReadOnly.Training_ScoreTypes.Where(p => p.Training_ScoreTypeKey == int.Parse(m_lScoreType[i].ToString())).ToList();
                m_dtScore.Columns.Add(st[0].Name.ToString() + "-Điểm số");
                m_dtScore.Columns.Add(st[0].Name.ToString() + "-Điểm chữ");
                m_dtScore.Columns.Add(st[0].Name.ToString() + "-Khóa", System.Type.GetType("System.Boolean"));
            }
            #endregion

            #region [Add Column SubjectScore and SubjectScoreFinal]
            if (m_lScoreType.Count > 0)
            {
                m_dtScore.Columns.Add("Học phần");
                m_dtScore.Columns.Add("Điểm kết thúc môn");
                btnLockAll.Enabled = true;
            }
            else
            {
                btnLockAll.Enabled = false;
            }
            //Chuyen sang thang diem 4 va diem chu 'Bang diem dai hoc va cao dang'
            //CheckLevel(GetSubjectClassKey()) != -1 &&  
            if (CheckLevel(GetSubjectClassKey()) != (int)DefaultConfig.Catalogue_Level.Intermediate)
            {
                Training_Subject_ClassInfo infoSubjectClass = new Training_Subject_ClassInfo(subjectClassKey);
                if (infoSubjectClass.Properties.Yearly == false || infoSubjectClass.Properties.Yearly == null)
                {
                    m_dtScore.Columns.Add("Thang điểm 4");
                    m_dtScore.Columns.Add("Điểm chữ");
                }
            }
            //Trung cap
            m_dtScore.Columns.Add("Ghi chú");
            #endregion
            if (m_data.m_DCReadOnly.Training_Scores.Check(subjectClassKey) == true)
            {
                try
                {
                    #region  [Output scores]
                    DataTable _dtScoreList = new DataTable();
                    _dtScoreList = m_data.m_DCReadOnly.Training_Scores.getScores(GetSubjectClassKey()).ToDataTable();
                    for (int j = 0; j < m_lScoreType.Count; j++)//ScoreType List
                    {
                        DataTable _dtScoreListByScoreType = new DataTable();
                        DataRow[] _drScoreListByScoreType = _dtScoreList.Select("[Training_ScoreTypeKey]='"+m_lScoreType[j].ToString()+"'");
                        _dtScoreListByScoreType = _dtScoreList.Clone();
                        foreach(DataRow dr in _drScoreListByScoreType)
                        {
                            _dtScoreListByScoreType.ImportRow(dr);
                        }
                        int k = m_dtInfoStudent.Columns.Count + j * 3;
                        if (m_data.m_DCReadOnly.Training_Scores.CheckSubjectClassScoreType(
                                            subjectClassKey, Convert.ToInt32(m_lScoreType[j].ToString())) == true)
                        {//Check ScoreType has been inputed?
                            if (_dtScoreListByScoreType.Rows.Count > 0)
                            {
                                Training_SubjectClass_ScoreTypeInfo infoSubjectClassScoreType = new Training_SubjectClass_ScoreTypeInfo(GetSubjectClassKey(), m_lScoreType[j]);
                                if (infoSubjectClassScoreType.Properties.Lock == true)
                                {
                                    #region [ScoreType Locked]
                                    for (int i = 0; i < m_dtInfoStudent.Rows.Count; i++)
                                    {
                                        for (int l = 0; l < _dtScoreListByScoreType.Rows.Count; l++)
                                        {
                                            if (m_dtScore.Rows[i]["SVKey"].ToString() == _dtScoreListByScoreType.Rows[l]["Training_StudentKey"].ToString())
                                            {
                                                m_dtScore.Rows[i][k] = _dtScoreListByScoreType.Rows[l]["Score"].ToString();
                                                m_dtScore.Rows[i]["Ghi chú"] = _dtScoreListByScoreType.Rows[l]["Note"].ToString();
                                                if (_dtScoreListByScoreType.Rows[l]["Score"] != null && _dtScoreListByScoreType.Rows[l]["Score"].ToString() != "")
                                                {
                                                    string _strScoreLetter = m_cReadnumber.Convert(_dtScoreListByScoreType.Rows[l]["Score"].ToString(), '.', " chấm ");
                                                    m_dtScore.Rows[i][k + 1] = UppercaseFirst(_strScoreLetter);
                                                }
                                                _dtScoreListByScoreType.Rows[l].Delete();
                                            }
                                        }
                                        m_dtScore.Rows[i][k + 2] = true;
                                    }
                                    #endregion
                                }
                                else
                                {
                                    #region [ScoreType don't lock]
                                    for (int i = 0; i < m_dtInfoStudent.Rows.Count; i++)
                                    {
                                        for (int l = 0; l < _dtScoreListByScoreType.Rows.Count; l++)
                                        {
                                            if (m_dtScore.Rows[i]["SVKey"].ToString() == _dtScoreListByScoreType.Rows[l]["Training_StudentKey"].ToString())
                                            {
                                                m_dtScore.Rows[i][k] = _dtScoreListByScoreType.Rows[l]["Score"].ToString();
                                                if (_dtScoreListByScoreType.Rows[l]["OnlyRead"] != null && _dtScoreListByScoreType.Rows[l]["OnlyRead"].ToString() != "")
                                                {
                                                    m_dtScore.Rows[i][k + 2] = bool.Parse(_dtScoreListByScoreType.Rows[l]["OnlyRead"].ToString());
                                                }
                                                else
                                                {
                                                    m_dtScore.Rows[i][k + 2] = false;
                                                }
                                                m_dtScore.Rows[i]["Ghi chú"] = _dtScoreListByScoreType.Rows[l]["Note"].ToString();
                                                if (_dtScoreListByScoreType.Rows[l]["Score"] != null && _dtScoreListByScoreType.Rows[l]["Score"].ToString() != "")
                                                {
                                                    string _strScoreLetter = m_cReadnumber.Convert(_dtScoreListByScoreType.Rows[l]["Score"].ToString(), '.', " chấm ");
                                                    m_dtScore.Rows[i][k + 1] = UppercaseFirst(_strScoreLetter);
                                                }
                                                _dtScoreListByScoreType.Rows[l].Delete();
                                            }
                                        }
                                    }
                                    #endregion
                                }
                            }
                        }////////////
                        else
                        {
                            for (int i = 0; i < m_dtInfoStudent.Rows.Count; i++)
                            {
                                m_dtScore.Rows[i][k + 2] = false;
                            }
                        }
                    }
                    #endregion
                    #region [Show AverageScoreFinal]
                    DataTable dtAverageScoreFinal = new DataTable();
                    dtAverageScoreFinal.Clear();
                    m_data = new DBMain();
                    dtAverageScoreFinal = m_data.m_DCReadOnly.Training_Student_Subject_Classes.GetList(m_data.m_DCReadOnly.Training_Students,
                        m_data.m_DCReadOnly.Training_Student_Classes, subjectClassKey).ToDataTable();
                    for (int l = 0; l < m_dtScore.Rows.Count; l++)
                    {
                        if (dtAverageScoreFinal.Rows[l]["AverageScoreFinal"] != null)
                        {
                            if (dtAverageScoreFinal.Rows[l]["AverageScoreFinal"].ToString() != "")
                            {
                                m_dtScore.Rows[l]["Điểm kết thúc môn"] = dtAverageScoreFinal.Rows[l]["AverageScoreFinal"].ToString();
                            }
                        }
                    }
                    #endregion
                }
                catch { }
            }
            else
            {
                #region [Input scores]
                for (int j = 0; j < m_lScoreType.Count; j++)
                {
                    int k = m_dtInfoStudent.Columns.Count + j * 3;
                    for (int i = 0; i < m_dtInfoStudent.Rows.Count; i++)
                    {
                        m_dtScore.Rows[i][k + 2] = false;
                    }
                }
                #endregion
            }
            #region [Set DataSource]
            for (int j = 0; j < m_lScoreType.Count; j++)
            {
                int k = m_dtInfoStudent.Columns.Count + j * 3;
                for (int i = 0; i < m_dtScore.Rows.Count; i++)
                {
                    if (m_dtScore.Rows[i][k + 2] == null || m_dtScore.Rows[i][k+2].ToString() =="")
                    {
                        m_dtScore.Rows[i][k + 2] = false;
                    }
                }
            }
            this.gctScore.DataSource = m_dtScore;
            this.grvScore.PopulateColumns();
            #endregion

            #region [Show locks]
            for (int j = 0; j < m_lScoreType.Count; j++)
            {
                int k = m_dtInfoStudent.Columns.Count + j * 3;
                for (int i = 0; i < m_dtInfoStudent.Rows.Count; i++)
                {
                    grvScore.Columns[k + 2].ColumnEdit = repositoryItemCheckEdit1;
                }
            }
            #endregion

            #region [Column Subject Score]
            if (m_lScoreType.Count > 0 && m_data.m_DCReadOnly.Training_Scores.Check(subjectClassKey) == true)
            {
                grvScore.BeginUpdate();
                //Tinh diem trung binh dai hoc va cao dang
                if (CheckLevel(GetSubjectClassKey()) != (int)DefaultConfig.Catalogue_Level.Intermediate)
                {
                   CaculateFinalScore(subjectClassKey);
                }
                else //Tinh diem trung binh trung cap
                {
                    CaculateFinalScoreIntermediate(subjectClassKey);
                }
                grvScore.EndUpdate();
            }
            #endregion

            #region [Interface: center text]
            for (int i = 0; i < grvScore.Columns.Count; i++)
            {
                if (i > 3)
                {
                    grvScore.Columns[i].AppearanceCell.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center;
                    grvScore.Columns[i].AppearanceCell.TextOptions.VAlignment = DevExpress.Utils.VertAlignment.Center;
                }
            }
            grvScore.Columns[0].Visible = false;
            #endregion

            #region [List Score Edit]
            if (m_eType == eFuncTions.Check || m_eType == eFuncTions.View)
            {
                this.m_dtDraw = new DataTable();
                this.m_dtDraw = m_data.m_DCReadOnly.Log_ScoreEdits.GetList(subjectClassKey).ToDataTable();
            }
            #endregion

            #region [Convert Scale 4 and ScoreLetter for University and Colleges]
            if (CheckLevel(GetSubjectClassKey()) != (int)DefaultConfig.Catalogue_Level.Intermediate)
            {
                for (int i = 0; i < grvScore.RowCount; i++)
                {
                    if (grvScore.GetRowCellValue(i, grvScore.Columns["Điểm kết thúc môn"]) != null)//Học phần
                    {
                        if (grvScore.GetRowCellValue(i, grvScore.Columns["Điểm kết thúc môn"]).ToString() != "")
                        {
                            try
                            {
                                double score = Convert.ToDouble(grvScore.GetRowCellValue(i, grvScore.Columns["Điểm kết thúc môn"]).ToString());
                                grvScore.SetRowCellValue(i, grvScore.Columns["Thang điểm 4"], ChangeScoreNumber(score).ToString());
                                grvScore.SetRowCellValue(i, grvScore.Columns["Điểm chữ"], ChangeScoreLetter(score));
                            }
                            catch { }
                        }
                    }
                }
            }
            #endregion

            #endregion
        }
        /// <summary>
        /// Tinh diem hoc phan
        /// </summary>
        /// <param name="subjectClassKey"></param>
        /// <param name="row"></param>
        private void CaculateFinalScore(int subjectClassKey,int row = -1)
        {
            Training_SubjectClass_ScoreTypeInfo infoType = new Training_SubjectClass_ScoreTypeInfo();
            if (infoType.CheckScoreTypeCount(m_data.m_DCReadOnly.Training_SubjectClass_ScoreTypes, subjectClassKey)==true)
            {
                //Phan tram diem so
                List<float> _lPercents = new List<float>();
                _lPercents = m_lPpercent;
                Training_Subject_ClassInfo infoClass = new Training_Subject_ClassInfo(subjectClassKey);
                if (infoClass.Properties.Yearly == true) //Lop nien che
                {
                    Training_SubjectClass_ScoreTypeInfo infoClassType = new Training_SubjectClass_ScoreTypeInfo();
                    if (infoClassType.CheckClassScoreType(m_data.m_DCReadOnly.Training_SubjectClass_ScoreTypes,
                        subjectClassKey, int.Parse(DefaultConfig.SCORETYPE_3.ToString())) == true)//Kiem tra co diem lan 2
                    {
                        int column = m_dtInfoStudent.Columns.Count + (m_lScoreType.Count - 1) * 3;
                        for (int i = 0; i < grvScore.RowCount; i++)
                        {
                            if (i == row || row == -1)
                            {
                                double hpnc = 0;
                                if (grvScore.GetRowCellValue(i, grvScore.Columns[column]) != null)
                                {
                                    if (grvScore.GetRowCellValue(i, grvScore.Columns[column]).ToString() != "")
                                    {
                                        for (int j = 0; j < m_lScoreType.Count; j++)
                                        {
                                            if (m_lScoreType[j].ToString() != DefaultConfig.SCORETYPE_2)
                                            {
                                                int k = m_dtInfoStudent.Columns.Count + j * 3;
                                                if (grvScore.GetRowCellValue(i, grvScore.Columns[k]) != null)
                                                {
                                                    if (grvScore.GetRowCellValue(i, grvScore.Columns[k]).ToString() != "")
                                                    {
                                                        float score = float.Parse(grvScore.GetRowCellValue(i, grvScore.Columns[k]).ToString());
                                                        hpnc += score * _lPercents[j];
                                                    }
                                                }
                                            }
                                        }
                                        grvScore.SetRowCellValue(i, grvScore.Columns["Học phần"], Math.Round(hpnc, 0));
                                    }
                                    else
                                    {
                                        for (int j = 0; j < m_lScoreType.Count; j++)
                                        {
                                            if (m_lScoreType[j].ToString() != DefaultConfig.SCORETYPE_3)
                                            {
                                                try
                                                {
                                                    int k = m_dtInfoStudent.Columns.Count + j * 3;
                                                    float score = float.Parse(grvScore.GetRowCellValue(i, grvScore.Columns[k]).ToString());
                                                    hpnc += score * _lPercents[j];
                                                }
                                                catch { }
                                            }
                                        }
                                        grvScore.SetRowCellValue(i, grvScore.Columns["Học phần"], Math.Round(hpnc, 0));
                                    }
                                }
                                else
                                {
                                    for (int j = 0; j < m_lScoreType.Count; j++)
                                    {
                                        if (m_lScoreType[j].ToString() != DefaultConfig.SCORETYPE_3)
                                        {
                                            int k = m_dtInfoStudent.Columns.Count + j * 3;
                                            if(grvScore.GetRowCellValue(i, grvScore.Columns[k]) != null)
                                            {
                                                if (grvScore.GetRowCellValue(i, grvScore.Columns[k]).ToString() != "")
                                                {
                                                    float score = float.Parse(grvScore.GetRowCellValue(i, grvScore.Columns[k]).ToString());
                                                    hpnc += score * _lPercents[j];
                                                }
                                            }
                                        }
                                    }
                                    grvScore.SetRowCellValue(i, grvScore.Columns["Học phần"], Math.Round(hpnc, 0));
                                }
                            }
                        }
                    }
                    else
                    {
                        for (int i = 0; i < grvScore.RowCount; i++)
                        {
                            double hptc = 0;
                            for (int j = 0; j < m_lScoreType.Count; j++)
                            {
                                int k = m_dtInfoStudent.Columns.Count + j * 3;
                                Training_ScoreTypeInfo infoScoreType = new Training_ScoreTypeInfo(m_lScoreType[j]);
                                if (grvScore.GetRowCellValue(i, grvScore.Columns[k]) != null)
                                {
                                    if (grvScore.GetRowCellValue(i, grvScore.Columns[k]).ToString() != "")
                                    {
                                        float score = float.Parse(grvScore.GetRowCellValue(i, grvScore.Columns[k]).ToString());
                                        hptc += score * _lPercents[j];
                                    }
                                }
                            }
                            grvScore.SetRowCellValue(i, grvScore.Columns["Học phần"], Math.Round(hptc, 0));
                        }
                    }
                }
                else //Lop tin chi
                {
                    for (int i = 0; i < grvScore.RowCount; i++)
                    {
                        double hptc = 0;
                        for (int j = 0; j < m_lScoreType.Count; j++)
                        {
                            int k = m_dtInfoStudent.Columns.Count + j * 3;
                            if (grvScore.GetRowCellValue(i, grvScore.Columns[k]) != null)
                            {
                                if (grvScore.GetRowCellValue(i, grvScore.Columns[k]).ToString() != "")
                                {
                                    double score = double.Parse(grvScore.GetRowCellValue(i, grvScore.Columns[k]).ToString());
                                    hptc += score * _lPercents[j];
                                }
                            }
                        }
                        grvScore.SetRowCellValue(i, grvScore.Columns["Học phần"], Math.Round(hptc, 1));
                    }
                }
            }
        }
        /// <summary>
        /// Tinh diem hoc phan trung cap
        /// </summary>
        /// <param name="subjectClassKey"></param>
        /// <param name="row"></param>
        private void CaculateFinalScoreIntermediate(int subjectClassKey, int row = -1)
        {
            Training_Subject_ClassInfo infoClass = new Training_Subject_ClassInfo(subjectClassKey);
            Training_SubjectClass_ScoreTypeInfo infoScoreType = new Training_SubjectClass_ScoreTypeInfo();
            if (infoScoreType.CheckScoreTypeCount(m_data.m_DCReadOnly.Training_SubjectClass_ScoreTypes, subjectClassKey) == true)
            {
                for (int i = 0; i < grvScore.RowCount; i++)
                {
                    double _dHPTC = 0;
                    double _dGK = 0;
                    int _iSumCoefficient = 0;
                    for (int j = 0; j < m_lScoreType.Count; j++)
                    {
                        int k = m_dtInfoStudent.Columns.Count + j * 3;
                        if (j != m_lScoreType.Count-1)//tinh diem giua ki
                        {
                            _iSumCoefficient += m_lCoefficient[j];
                            if (grvScore.GetRowCellValue(i, grvScore.Columns[k]) != null &&
                                grvScore.GetRowCellValue(i, grvScore.Columns[k]).ToString() != "")
                            {
                                _dGK += Convert.ToDouble(grvScore.GetRowCellValue(i, grvScore.Columns[k]).ToString())* m_lCoefficient[j];
                            }
                        }
                        else//Tinh diem hoc phan
                        {
                            if (grvScore.GetRowCellValue(i, grvScore.Columns[k]) != null &&
                                grvScore.GetRowCellValue(i, grvScore.Columns[k]).ToString() != "")
                            {
                                //double 
                                _dHPTC = Math.Round((Convert.ToDouble(grvScore.GetRowCellValue(i, grvScore.Columns[k]).ToString()) +
                                            Math.Round(_dGK / _iSumCoefficient, 0, MidpointRounding.AwayFromZero)) / 2, 1, MidpointRounding.AwayFromZero);
                            }
                            else
                            {
                                _dHPTC = Math.Round(_dGK / _iSumCoefficient, 0, MidpointRounding.AwayFromZero);
                            }
                        }
                    }
                    grvScore.SetRowCellValue(i, grvScore.Columns["Học phần"], Math.Round(_dHPTC, 1));
                }
            }
        }
        /// <summary>
        /// Tinh diem trung binh tich luy cua lop hoc phan
        /// </summary>
        /// <param name="dtInfo"></param>
        /// <param name="dtStudentID"></param>
        private void CaculateAverageScoreAccumulates(DataTable dtInfo, DataTable dtStudentID)
        {
            DataTable _dtScore = dtInfo;
            for (int j = 0; j < dtStudentID.Rows.Count; j++)
            {
                string _strStudentId = dtStudentID.Rows[j]["ID"].ToString();
                DataTable _dtScoreofStudent = new DataTable();
                DataRow[] _drResult = _dtScore.Select("[ID]='" + _strStudentId + "'");
                _dtScoreofStudent = _dtScore.Clone();
                foreach (DataRow _dr in _drResult)
                {
                    _dtScoreofStudent.ImportRow(_dr);
                }
                _dtScoreofStudent.Columns.Add("HPTC");
                double _dCreditAcc = 0;
                double _dScoreAcc = 0;
                double _dCredit = 0;
                double _dScore = 0;
                for (int i = 0; i < _dtScoreofStudent.Rows.Count; i++)
                {
                    _dtScoreofStudent.Rows[i]["HPTC"] = Convert.ToDouble(_dtScoreofStudent.Rows[i]["AverageScoreFinal"].ToString()) *
                                            Convert.ToDouble(_dtScoreofStudent.Rows[i]["TotalCredits"].ToString());
                    if (Convert.ToDouble(_dtScoreofStudent.Rows[i]["AverageScoreFinal"].ToString()) >= DefaultConfig.MinScorePass_NoYearly)
                    {
                        _dCreditAcc += Convert.ToDouble(_dtScoreofStudent.Rows[i]["TotalCredits"].ToString());
                        _dScoreAcc += Convert.ToDouble(_dtScoreofStudent.Rows[i]["HPTC"].ToString());
                    }
                    _dCredit += Convert.ToDouble(_dtScoreofStudent.Rows[i]["TotalCredits"].ToString());
                    _dScore += Convert.ToDouble(_dtScoreofStudent.Rows[i]["HPTC"].ToString());
                }
                double averageScoreAcc = 0;
                if (_dScoreAcc != 0)
                {
                    averageScoreAcc = Math.Round(_dScoreAcc / _dCreditAcc, 2, MidpointRounding.AwayFromZero);
                }
                double averageScore = 0;
                if (_dScore != 0)
                {
                    averageScore = Math.Round(_dScore / _dCredit, 2, MidpointRounding.AwayFromZero);
                }
                Training_Student_ClassInfo infoStudentClass = new Training_Student_ClassInfo(_strStudentId);
                infoStudentClass.Properties.AverageScoreAccumulate = averageScoreAcc;
                infoStudentClass.Properties.AverageScoreNoAccumulate = averageScore;
                infoStudentClass.Properties.TotalCreditAccumulate = _dCreditAcc;
                infoStudentClass.Save();
            }
        }
        /// <summary>
        /// Tinh diem trung binh tich luy mot sinh vien
        /// </summary>
        /// <param name="dtInfo"></param>
        /// <param name="strStudentID"></param>
        private void CaculateAverageScoreAccumulate(DataTable dtInfo, string strStudentID)
        {
            DataTable _dtScore = dtInfo;
            string _strStudentId = strStudentID;
            _dtScore.Columns.Add("HPTC");
            double _dCreditAcc = 0;
            double _dScoreAcc = 0;
            double _dCredit = 0;
            double _dScore = 0;
            for (int i = 0; i < _dtScore.Rows.Count; i++)
            {
                _dtScore.Rows[i]["HPTC"] = Convert.ToDouble(_dtScore.Rows[i]["AverageScoreFinal"].ToString()) *
                                        Convert.ToDouble(_dtScore.Rows[i]["TotalCredits"].ToString());
                if (Convert.ToDouble(_dtScore.Rows[i]["AverageScoreFinal"].ToString()) >= DefaultConfig.MinScorePass_NoYearly)
                {
                    _dCreditAcc += Convert.ToDouble(_dtScore.Rows[i]["TotalCredits"].ToString());
                    _dScoreAcc += Convert.ToDouble(_dtScore.Rows[i]["HPTC"].ToString());
                }
                _dCredit += Convert.ToDouble(_dtScore.Rows[i]["TotalCredits"].ToString());
                _dScore += Convert.ToDouble(_dtScore.Rows[i]["HPTC"].ToString());
            }
            double _dAverageScoreAcc = 0;
            if (_dScoreAcc != 0)
            {
                _dAverageScoreAcc = Math.Round(_dScoreAcc / _dCreditAcc, 2, MidpointRounding.AwayFromZero);
            }
            double _dAverageScore = 0;
            if (_dScore != 0)
            {
                _dAverageScore = Math.Round(_dScore / _dCredit, 2, MidpointRounding.AwayFromZero);
            }
            Training_Student_ClassInfo infoStudentClass = new Training_Student_ClassInfo(_strStudentId);
            infoStudentClass.Properties.AverageScoreAccumulate = _dAverageScoreAcc;
            infoStudentClass.Properties.AverageScoreNoAccumulate = _dAverageScore;
            infoStudentClass.Properties.TotalCreditAccumulate = _dCreditAcc;
            infoStudentClass.Save();
        }
        /// <summary>
        /// Lay thong tin lop hoc phan
        /// </summary>
        /// <param name="subjectClassKey"></param>
        private void GetAllInfo(int subjectClassKey)
        {
            try
            {
                //Thông tin lớp học phần
                Training_Subject_ClassInfo infoClass = new Training_Subject_ClassInfo(subjectClassKey);
                if (infoClass.Properties.Yearly == true)
                {
                    m_dMinScorePass = DefaultConfig.MinScorePass_Yearly;
                }
                else
                {
                    m_dMinScorePass = DefaultConfig.MinScorePass_NoYearly;
                }
                //danh sach sinh vien
                m_dtInfoStudent = m_data.m_DCReadOnly.Training_Student_Subject_Classes.GetStudentsSubjectClass(m_data.m_DCReadOnly.Training_Student_Classes,
                                m_data.m_DCReadOnly.Training_Students, subjectClassKey).ToDataTable();

                //danh sach loai diem
                m_lScoreType = m_data.m_DCReadOnly.Training_SubjectClass_ScoreTypes.getListScoreTypeClass(m_data.m_DCReadOnly.Training_ScoreTypes, subjectClassKey);
                for (int j = 0; j < m_lScoreType.Count; j++)
                {
                    //Add danh sach phan tram cac loai diem
                    Training_SubjectClass_ScoreTypeInfo infoClassScoreType = new Training_SubjectClass_ScoreTypeInfo(subjectClassKey, m_lScoreType[j]);
                    float percent = float.Parse(infoClassScoreType.Properties.DefaultPercent.ToString()) / 100;
                    m_lPpercent.Add(percent);
                    //Add danh sach he so cac loai diem
                    if (j != m_lScoreType.Count - 1)
                    {
                        Training_ScoreTypeInfo infoScoreType = new Training_ScoreTypeInfo(m_lScoreType[j]);
                        if (infoScoreType.Properties.Coefficient != null && infoScoreType.Properties.Coefficient.ToString() != "")
                        {
                            m_lCoefficient.Add(infoScoreType.Properties.Coefficient.ToInt());
                        }
                    }
                }
                Training_SubjectInfo infoSubject = new Training_SubjectInfo(infoClass.Properties.Training_SubjectKey.Value);
                Catalogue_DepartmentInfo infoDepartment = new Catalogue_DepartmentInfo(infoSubject.Properties.Catalogue_DepartmentKey.Value);
                txtDepartment.Text = infoDepartment.Properties.Name.ToString();
                txtSubjectName.Text = infoSubject.Properties.Name.ToString();
                txtIDSubject.Text = infoSubject.Properties.ID.ToString();
                txtSubjectClasssID.Text = infoClass.Properties.ID.ToString();
                txtSubjectClassName.Text = infoClass.Properties.Name.ToString();
                string level = infoSubject.Properties.ID.Substring(0, 1);
                switch (level)
                {
                    case "C":
                        txtLevel.Text = "Cao đẳng";
                        break;
                    case "D":
                        txtLevel.Text = "Đại học";
                        break;
                    case "T":
                        txtLevel.Text = "Trung cấp";
                        break;
                    default:
                        txtLevel.Text = "";
                        break;
                }
                Training_Subject_ClassInfo infoCredits = new Training_Subject_ClassInfo(subjectClassKey);
                DataTable dtCredits = infoCredits.TotalCredits(subjectClassKey).ToDataTable();
                txtCredits.Text = dtCredits.Rows[0]["TotalCredits"].ToString();
            }
            catch (Exception ex) { MessageBox.Show("James, lỗi. Thông tin lỗi:" + ex.Message); }
            this.grvScore.BeginDataUpdate();
            this.grvScore.BeginUpdate();
            //output score
            OutputScore(subjectClassKey);

            for (int i = 0; i < grvScore.Columns.Count; i++)
            {
                grvScore.Columns[i].OptionsColumn.AllowEdit = false;
                grvScore.Columns[i].BestFit();
            }
            xucBar1.btnSave.Enabled = false;
            xucBar1.btnCancel.Enabled = false;
            xucBar1.btnImportExcel.Enabled = false;
            xucBar1.btnEdit.Enabled = true;
            labelSubjectClassID.Text = null;
            this.grvScore.EndUpdate();
            this.grvScore.EndDataUpdate();
        }
        /// <summary>
        /// Kiem tra ten cot diem
        /// </summary>
        /// <param name="column"></param>
        /// <returns></returns>
        private int CheckColumn(string column)
        {
            int sClassKey = GetSubjectClassKey();
            //List<int> scoreType = m_Score.m_DCReadOnly.Training_SubjectClass_ScoreTypes.getListScoreTypeClass(m_Score.m_DCReadOnly.Training_ScoreTypes, lueTraining_Subject_Class.GetIntValue());
            List<int> scoreType = m_data.m_DCReadOnly.Training_SubjectClass_ScoreTypes.getListScoreTypeClass(m_data.m_DCReadOnly.Training_ScoreTypes, sClassKey);
            List<string> sType = new List<string>();
            for (int i = 0; i < scoreType.Count; i++)
            {
                var st = m_data.m_DCReadOnly.Training_ScoreTypes.Where(p => p.Training_ScoreTypeKey == int.Parse(scoreType[i].ToString())).ToList();
                sType.Add(st[0].Name.ToString());
            }
            int scoreChar = 0;
            int scoreLock = 0;
            int score = 0;
            for (int j = 0; j < sType.Count; j++)
            {
                string ds = ("col" + sType[j] + "-Điểm số").Replace(" ", "");
                string key = ("col" + sType[j] + "-Khóa").Replace(" ", "");
                if (column == ds)
                {
                    scoreChar++;
                }
                else if (column == key)
                {
                    scoreLock++;
                }
                else
                {
                    score++;
                }
            }
            if (scoreChar != 0)
            {
                return 1;
            }
            else if (scoreLock != 0)
            {
                return 2;
            }
            else if (score != 0)
            {
                return 0;
            }
            else
            {
                return 0;
            }
        }
        /// <summary>
        /// Dong tat ca khoa cua mot loai diem
        /// </summary>
        /// <param name="position"></param>
        private void LockAll(int position)
        {

            //DataTable m_dt1 = new DataTable();
            //m_dt1 = m_Score.m_DCReadOnly.Training_Student_Subject_Classes.GetStudentsSubjectClass(m_Score.m_DCReadOnly.Training_Student_Classes,
            //                        m_Score.m_DCReadOnly.Training_Students, lueTraining_Subject_Class.GetIntValue());

            //List<int> scoreType = m_Score.m_DCReadOnly.Training_SubjectClass_ScoreTypes.getListScoreTypeClass(m_Score.m_DCReadOnly.Training_ScoreTypes, lueTraining_Subject_Class.GetIntValue());
            //this.gctScore.DataSource = m_dt;
            //this.grvScore.PopulateColumns();
            //for (int j = 0; j < scoreType.Count; j++)
            //{
                int k = m_dtInfoStudent.Columns.Count + position * 3;
                for (int i = 0; i < m_dtInfoStudent.Rows.Count; i++)
                {
                    grvScore.SetRowCellValue(i, grvScore.Columns[k + 2], true);
                    grvScore.Columns[k + 2].ColumnEdit = repositoryItemCheckEdit1;
                }
            //}
            grvScore.Columns[0].Visible = false;

            //btnLockAll.Text = "Mở khóa tất cả";
            //btnLockAll.ImageIndex = 1;
        }
        /// <summary>
        /// Kiem tra loai diem nao da duoc nhap xong
        /// </summary>
        /// <param name="subjectClassKey"></param>
        /// <param name="scoreTypeList"></param>
        private void CheckScoreTypeLock(int subjectClassKey, List<int> scoreTypeList)
        {
            if (grvScore.Columns.Count > 6)
            {
                Training_Subject_ClassInfo infoSubjectClass = new Training_Subject_ClassInfo(subjectClassKey);
                for (int i = 0; i < scoreTypeList.Count(); i++)
                {
                    Training_ScoreTypeInfo infoScoreType = new Training_ScoreTypeInfo(scoreTypeList[i]);
                    Training_SubjectClass_ScoreTypeInfo infoSS = new Training_SubjectClass_ScoreTypeInfo(subjectClassKey, scoreTypeList[i]);
                    Training_Score_TaskInputInfo infoTask = new Training_Score_TaskInputInfo(
                                                                    m_gPersonelKey, subjectClassKey, SysDateTime.Now);
                    if (infoTask.Properties.Personnel_PersonnelKey == m_gPersonelKey)//con thoi gian nhap diem
                    {
                        if (infoTask.Properties.Training_Subject_ClassKey == subjectClassKey)
                        {                           
                            m_iScoreTypeLock = scoreTypeList[i];
                            m_iPosition = i;
                            btnLockAll.Enabled = true;
                            if (i != scoreTypeList.Count() - 1)//Nomal ScoreType
                            {
                                //grvScore.Columns["Điểm kết thúc môn"].OptionsColumn.AllowEdit = true;
                                if (CheckLevel(subjectClassKey) != (int)DefaultConfig.Catalogue_Level.Intermediate &&
                                    (infoSubjectClass.Properties.Yearly == false || infoSubjectClass.Properties.Yearly == null))
                                {
                                    grvScore.Columns["Thang điểm 4"].Visible = false;
                                    grvScore.Columns["Điểm chữ"].Visible = false;
                                }
                                if (infoSS.Properties.Lock != true)
                                {
                                    btnLockAll.Text = "Khóa điểm " + infoScoreType.Properties.Name.ToString();
                                    m_bScoreTypeLock = false;
                                    m_bFinishInput = false;
                                    break;
                                }
                                else
                                {
                                    m_bFinishInput = false;
                                }
                            }
                            else//Final ScoreType
                            {
                                grvScore.Columns["Điểm kết thúc môn"].OptionsColumn.AllowEdit = true;
                                if (CheckLevel(subjectClassKey) != (int)DefaultConfig.Catalogue_Level.Intermediate &&
                                    (infoSubjectClass.Properties.Yearly == false || infoSubjectClass.Properties.Yearly == null))
                                {
                                    grvScore.Columns["Thang điểm 4"].Visible = true;
                                    grvScore.Columns["Điểm chữ"].Visible = true;
                                }
                                if (infoSS.Properties.Lock != true)
                                {
                                    btnLockAll.Text = "Khóa điểm " + infoScoreType.Properties.Name.ToString();
                                    m_bScoreTypeLock = true;
                                    m_bFinishInput = false;
                                    
                                }
                                else
                                {
                                    btnLockAll.Text = "Nhập điểm hoàn tất";
                                    btnLockAll.Enabled = false;
                                    m_bFinishInput = true;
                                }
                            }
                        }
                        else
                        {
                            labelSubjectClassID.Text = "";
                            xucBar1.btnSave.Enabled = false;
                            xucBar1.btnImportExcel.Enabled = false;
                        }
                    }
                    else//het thoi gian nhap diem & chua phan cong nhap diem
                    {
                        btnLockAll.Enabled = false;
                        labelSubjectClassID.Text = "";
                        xucBar1.btnSave.Enabled = false;
                        xucBar1.btnImportExcel.Enabled = false;
                    }
                }
            }
        }
        /// <summary>
        /// Kiem tra loai diem nao duoc kiem tra xong
        /// </summary>
        /// <param name="subjectClassKey"></param>
        /// <param name="scoreTypeList"></param>
        private void CheckScoreTypeFinishInput(int subjectClassKey, List<int> scoreTypeList)
        {
            Guid personelKey = Guid.Parse(UniMana.Utils.LoginInfo.GblLoginInfo.sysLoginPersionalKey.ToString());
            for (int i = 0; i < scoreTypeList.Count(); i++)
            {
                Training_ScoreTypeInfo infoScoreType = new Training_ScoreTypeInfo(scoreTypeList[i]);
                Training_SubjectClass_ScoreTypeInfo infoSS = new Training_SubjectClass_ScoreTypeInfo(subjectClassKey, scoreTypeList[i]);
                Training_Score_TaskInputInfo infoTask = new Training_Score_TaskInputInfo(
                                                                personelKey, subjectClassKey, SysDateTime.Now, false);
                if (infoTask.Properties.Personnel_PersonnelKey == personelKey)
                {
                    if (infoTask.Properties.Training_Subject_ClassKey == subjectClassKey)
                    {
                        GetNamePercentScore(subjectClassKey);
                        m_iScoreTypeLock = scoreTypeList[i];
                        m_iPosition = i;
                        btnChecked.Enabled = true;
                        //btnRequired.Enabled = true;
                        //menuRequiredEditScore.Enabled = true;
                        if (i != scoreTypeList.Count() - 1)
                        {
                            if (infoSS.Properties.Check != true)
                            {
                                btnChecked.Text = "Kiểm tra điểm " + infoScoreType.Properties.Name.ToString();
                                m_bScoreTypeLock = false;
                                break;
                            }
                            else
                            { }
                        }
                        else
                        {
                            if (infoSS.Properties.Check != true)
                            {
                                btnChecked.Text = "Kiểm tra điểm " + infoScoreType.Properties.Name.ToString();
                                m_bScoreTypeLock = true;
                            }
                            else
                            {
                                btnChecked.Text = "Kiểm tra hoàn tất";
                                btnChecked.Enabled = false;
                            }
                        }
                    }
                    else
                    {
                        //labelSubjectClassID.Text = "Lớp chưa phân công kiểm tra điểm!";
                    }
                }
                else
                {
                    btnChecked.Enabled = false;
                    //btnRequired.Enabled = false;
                    //labelSubjectClassID.Text = "Lớp chưa phân công kiểm tra điểm!";
                }
            }
        }
        /// <summary>
        /// In hoa chu cai dau tien
        /// </summary>
        /// <param name="s"></param>
        /// <returns></returns>
        private string UppercaseFirst(string s)
        {
            if (string.IsNullOrEmpty(s))
	        {
	            return string.Empty;
	        }
	        char[] a = s.ToCharArray();
	        a[0] = char.ToUpper(a[0]);
	        return new string(a);
        }
        /// <summary>
        /// Xep loai 
        /// </summary>
        /// <param name="score"></param>
        /// <returns></returns>
        private string RankCredits(double score)
        {
            if (score >= 3.6)
            {
                return " Xuất sắc ";
            }
            else if (score >= 3.2)
            {
                return " Giỏi ";
            }
            else if (score >= 2.50)
            {
                return " Khá ";
            }
            else if (score >= 2)
            {
                return " Trung bình ";
            }
            else
            {
                return "";
            }
        }
        /// <summary>
        /// Quy doi thang diem 4
        /// </summary>
        /// <param name="score"></param>
        /// <returns></returns>
        private double ChangeScoreNumber(double score)
        {
            if (score >= 8.5)
            {
                return 4;
            }
            else if (score >= 8)
            {
                return 3.5;
            }
            else if (score >= 7)
            {
                return 3;
            }
            else if (score >= 6.5)
            {
                return 2.5;
            }
            else if (score >= 5.5)
            {
                return 2;
            }
            else if (score >= 5)
            {
                return 1.5;
            }
            else if (score >= 4)
            {
                return 1;
            }
            else
            {
                return 0;
            }
        }
        /// <summary>
        /// Chuyen doi diem so sang diem chu
        /// </summary>
        /// <param name="score"></param>
        /// <returns></returns>
        private string ChangeScoreLetter(double score)
        {
            if (score >= 8.5)
            {
                return "A";
            }
            else if (score >= 8)
            {
                return "B+";
            }
            else if (score >= 7)
            {
                return "B";
            }
            else if (score >= 6.5)
            {
                return "C+";
            }
            else if (score >= 5.5)
            {
                return "C";
            }
            else if (score >= 5)
            {
                return "D+";
            }
            else if (score >= 4)
            {
                return "D";
            }
            else
            {
                return "F";
            }
        }
        /// <summary>
        /// Luu diem
        /// </summary>
        private void SaveScore()
        {
            while (true)
            {
                if (m_lRowScore != null)
                {
                    if (m_lRowScore.Count > 0)
                    {
                        if (m_iPosition != m_lScoreType.Count - 1)
                        {
                            try
                            {
                                RowScore row = m_lRowScore[0];
                                if (row._dScore != null && row._dScore.ToString() != "")
                                {
                                    m_data.m_DCSave.SaveScore(row._gStudentKey, row._iSubjectClassKey, row._iScoreTypeKey, Convert.ToDouble(row._dScore.ToString()),
                                                                row._strNote, row._bLock, row._strStudentID);
                                }
                                else
                                {
                                    m_data.m_DCSave.SaveScore(row._gStudentKey, row._iSubjectClassKey, row._iScoreTypeKey, null,
                                                             row._strNote, row._bLock, row._strStudentID);
                                }
                                m_lRowScore.RemoveAt(0);
                            }
                            catch /*(Exception e)*/ { /*MessageBox.Show(e.Message);*/ continue; } //Hữu thêm Execption
                        }
                        else
                        {
                            try
                            {
                                RowScore row = m_lRowScore[0];
                                if (row._dScore != null && row._dScore.ToString() != "")
                                {
                                    if (row._dAverageScore != null && row._dAverageScore.ToString() != "")
                                    {
                                        m_data.m_DCSave.SaveScoreFinal(row._gStudentKey, row._iSubjectClassKey, row._iScoreTypeKey,
                                                                   Convert.ToDouble(row._dScore.ToString()),
                                                                    row._strNote, row._bLock, row._strStudentID,
                                                                    Convert.ToDouble(row._dAverageScore.ToString()), m_dMinScorePass);
                                    }
                                }
                                else
                                {
                                    if (row._dAverageScore != null && row._dAverageScore.ToString() != "")
                                    {
                                        m_data.m_DCSave.SaveScoreFinal(row._gStudentKey, row._iSubjectClassKey, row._iScoreTypeKey,
                                                                        null, row._strNote, row._bLock, row._strStudentID,
                                                                        Convert.ToDouble(row._dAverageScore.ToString()), m_dMinScorePass);
                                    }
                                }
                                m_lRowScore.RemoveAt(0);
                            }
                            catch /*(Exception e)*/ { /*MessageBox.Show(e.Message);*/ continue; } //Hữu thêm Execption
                        }
                    }
                }
                Thread.Sleep(10);
            }
        }
        /// <summary>
        /// Kiểm tra hệ
        /// </summary>
        /// <param name="subjectClassKey"></param>
        /// <returns></returns>
        private int CheckLevel(int subjectClassKey)
        {
            Training_Subject_ClassInfo infoSubjectClass = new Training_Subject_ClassInfo(subjectClassKey);
            if (infoSubjectClass.Properties.Training_ClassKey != null && infoSubjectClass.Properties.Training_ClassKey.ToString() != "")
            {
                Training_ClassInfo infoClass = new Training_ClassInfo(infoSubjectClass.Properties.Training_ClassKey.ToInt());
                //Catalogue_LevelInfo infoLevel = new Catalogue_LevelInfo(infoClass.Properties.Catalogue_LevelKey.ToInt());
                return infoClass.Properties.Catalogue_LevelKey.ToInt();
            }
            else
            {
                return -1;
            }
        }
        /// <summary>
        /// Hien thi ten va phan tram cac loai diem
        /// </summary>
        /// <param name="subjectClassKey"></param>
        private void GetNamePercentScore(int subjectClassKey)
        {
            Training_Subject_ClassInfo sClassID = new Training_Subject_ClassInfo(subjectClassKey);
            string _strPercent = "";
            for (int j = 0; j < m_lScoreType.Count; j++)
            {
                Training_ScoreTypeInfo infoScoreType = new Training_ScoreTypeInfo(m_lScoreType[j]);
                Training_SubjectClass_ScoreTypeInfo infoSubjectClassScoreType = new Training_SubjectClass_ScoreTypeInfo(subjectClassKey, m_lScoreType[j]);
                if (j != m_lScoreType.Count - 1)
                {
                    _strPercent += infoScoreType.Properties.Name.ToString() + " : " + infoSubjectClassScoreType.Properties.DefaultPercent + "% - ";
                }
                else
                {
                    _strPercent += infoScoreType.Properties.Name.ToString() + " : " + infoSubjectClassScoreType.Properties.DefaultPercent + "%";
                }
            }
            //Dai hoc & cao dang
            if (CheckLevel(subjectClassKey) != (int)DefaultConfig.Catalogue_Level.Intermediate)
            {
                labelSubjectClassID.Text = "Bảng điểm lớp học phần: " + sClassID.Properties.ID.ToString() + "\n(" + _strPercent + ")";
            }
            else //Trung cap
            {
                labelSubjectClassID.Text = "Bảng điểm lớp học phần: " + sClassID.Properties.ID.ToString();
            }
            int _iWidth = panelControl1.Width;
            labelSubjectClassID.Location = new System.Drawing.Point(_iWidth / 2 - labelSubjectClassID.Width / 2, labelSubjectClassID.Location.Y);
        }
        #endregion
        #region [Menus]
        /// <summary>
        /// Menu xem diem theo hoc ki
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void menuViewScore_Click(object sender, EventArgs e)
        {
            if (grvScore.RowCount > 0)
            {
                try
                {
                    string studentID = grvScore.GetFocusedRowCellValue(grvScore.Columns["MSSV"]).ToString();
                    DataTable _dtProgram = new DataTable();
                    _dtProgram = m_data.m_DCReadOnly.Training_TrainingPrograms.GetTrainingProgramByStudentID(m_data.m_DCReadOnly.Training_Student_Classes,
                        studentID).ToDataTable();
                    if (_dtProgram.Rows.Count >= 2)
                    {
                        FrmScore_ChooseTrainingProgram f = new FrmScore_ChooseTrainingProgram(studentID);
                        f.ShowDialog();
                    }
                    else
                    {
                        SubFrmView_Student_Scores_ByTerm f = new SubFrmView_Student_Scores_ByTerm(studentID, _dtProgram.Rows[0]["Training_TrainingProgramKey"].ToString().ToInt());
                        f.ShowDialog();
                    }
                }
                catch { }
            }
        }
        /// <summary>
        /// Menu xem danh sach rot hoc phan
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void menuViewScores_Click(object sender, EventArgs e)
        {
            if (m_lScoreType.Count > 0 && m_data.m_DCReadOnly.Training_Scores.Check(GetSubjectClassKey()) == true)
            {
                //if (m_bCanChange == true)
                //{
                    DataTable dt = new DataTable();
                    dt.Columns.Add("Training_StudentKey");
                    dt.Columns.Add("ID");
                    dt.Columns.Add("LastName");
                    dt.Columns.Add("SureName");
                    dt.Columns.Add("Birthday");
                    dt.Columns.Add("Gender");
                    Training_Subject_ClassInfo infoSClass = new Training_Subject_ClassInfo(txtSubjectClassID.Text);
                    if (infoSClass.Properties.Yearly == true)
                    {
                        for (int i = 0; i < grvScore.RowCount; i++)
                        {
                            if (float.Parse(grvScore.GetRowCellValue(i, "Học phần").ToString()) < 5)
                            {
                                dt.Rows.Add(new object[] { grvScore.GetRowCellValue(i, "SVKey").ToString(), grvScore.GetRowCellValue(i, "MSSV").ToString(),
                                        grvScore.GetRowCellValue(i, "Họ lót").ToString(),  grvScore.GetRowCellValue(i, "Tên").ToString(),
                            grvScore.GetRowCellValue(i, "Ngày Sinh").ToString(), grvScore.GetRowCellValue(i, "Giới tính").ToString()});
                            }
                        }
                    }
                    else
                    {
                        for (int i = 0; i < grvScore.RowCount; i++)
                        {
                            if (float.Parse(grvScore.GetRowCellValue(i, "Học phần").ToString()) < 4)
                            {
                                dt.Rows.Add(new object[] { grvScore.GetRowCellValue(i, "SVKey").ToString(), grvScore.GetRowCellValue(i, "MSSV").ToString(),
                                        grvScore.GetRowCellValue(i, "Họ lót").ToString(),  grvScore.GetRowCellValue(i, "Tên").ToString(),
                            grvScore.GetRowCellValue(i, "Ngày Sinh").ToString(), grvScore.GetRowCellValue(i, "Giới tính").ToString()});
                            }
                        }
                    }
                    if (dt.Rows.Count > 0)
                    {
                        Training_Subject_ClassInfo info = new Training_Subject_ClassInfo(GetSubjectClassKey());
                        FrmScore_SubTransScripts f = new FrmScore_SubTransScripts(info.Properties.ID.ToString(), dt, true, txtCredits.Text);
                    }
                    else
                    {
                        XtraMessageBox.Show("Lớp không có sinh viên rớt!", "Thông báo");
                    }
                //}
                //else
                //{
                //    XtraMessageBox.Show("qưqwqwq");
                //}
            }
        }
        /// <summary>
        /// Menu In bang diem thi lai
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void menuPrintTranscripts_Click(object sender, EventArgs e)
        {
            if (m_lScoreType.Count > 0 && m_data.m_DCReadOnly.Training_Scores.Check(GetSubjectClassKey()) == true)
            {
                //if (m_bCanChange == true)
                //{
                    DataTable dt = new DataTable();
                    dt.Columns.Add("Training_StudentKey");
                    dt.Columns.Add("ID");
                    dt.Columns.Add("LastName");
                    dt.Columns.Add("SureName");
                    dt.Columns.Add("Birthday");
                    dt.Columns.Add("Gender");
                    Training_Subject_ClassInfo infoSClass = new Training_Subject_ClassInfo(txtSubjectClassID.Text);
                    if (infoSClass.Properties.Yearly == true)
                    {
                        for (int i = 0; i < grvScore.RowCount; i++)
                        {
                            if (float.Parse(grvScore.GetRowCellValue(i, "Học phần").ToString()) < 5)
                            {
                                dt.Rows.Add(new object[] { grvScore.GetRowCellValue(i, "SVKey").ToString(), grvScore.GetRowCellValue(i, "MSSV").ToString(),
                                        grvScore.GetRowCellValue(i, "Họ lót").ToString(),  grvScore.GetRowCellValue(i, "Tên").ToString(),
                            grvScore.GetRowCellValue(i, "Ngày Sinh").ToString(), grvScore.GetRowCellValue(i, "Giới tính").ToString()});
                            }
                        }
                    }
                    else
                    {
                        for (int i = 0; i < grvScore.RowCount; i++)
                        {
                            if (float.Parse(grvScore.GetRowCellValue(i, "Học phần").ToString()) < 4)
                            {
                                dt.Rows.Add(new object[] { grvScore.GetRowCellValue(i, "SVKey").ToString(), grvScore.GetRowCellValue(i, "MSSV").ToString(),
                                        grvScore.GetRowCellValue(i, "Họ lót").ToString(),  grvScore.GetRowCellValue(i, "Tên").ToString(),
                            grvScore.GetRowCellValue(i, "Ngày Sinh").ToString(), grvScore.GetRowCellValue(i, "Giới tính").ToString()});
                            }
                        }
                    }
                    if (dt.Rows.Count > 0)
                    {
                        Training_Subject_ClassInfo info = new Training_Subject_ClassInfo(GetSubjectClassKey());
                        FrmScore_SubTransScripts f = new FrmScore_SubTransScripts(info.Properties.ID.ToString(), dt, false, txtCredits.Text);
                    }
                    else
                    {
                        XtraMessageBox.Show("Lớp không có sinh viên rớt!", "Thông báo");
                    }
                //}
            }
        }
        /// <summary>
        /// Menu yeu cau sua diem
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void menuRequiredEditScore_Click(object sender, EventArgs e)
        {
            if (grvScore.RowCount > 0)
            {
                for (int i = 0; i < m_lScoreType.Count; i++)
                {
                    int k = m_dtInfoStudent.Columns.Count + i * 3;
                    if (grvScore.FocusedColumn.VisibleIndex == k-1)
                    {
                        if (bool.Parse(grvScore.GetFocusedRowCellValue(grvScore.Columns[k + 2]).ToString()) == true)
                        {
                            try
                            {
                                string _strStudentKey = grvScore.GetFocusedRowCellValue(grvScore.Columns["SVKey"]).ToString();
                                Training_Student_Subject_ClassInfo infoStudentSubjectClass = new Training_Student_Subject_ClassInfo(_strStudentKey, GetSubjectClassKey());
                                int _iProgramKey = Convert.ToInt32(infoStudentSubjectClass.Properties.Training_TrainingProgramKey.ToString());
                                Guid studentKey = Guid.Parse(grvScore.GetFocusedRowCellValue(grvScore.Columns[0]).ToString());
                                Frm_Score2_ScoreEditRequire re = new Frm_Score2_ScoreEditRequire(GetSubjectClassKey(), studentKey, m_lScoreType[i], _iProgramKey);
                                re.ShowDialog();
                            }
                            catch { }
                            break;
                        }
                        else
                        {
                            XtraMessageBox.Show("Điểm chưa khóa!","Thông báo");
                            break;
                        }
                    }
                }
            }
        }
        /// <summary>
        /// Menu them sinh vien vao lop 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void menuAddStudentSubjectClass_Click(object sender, EventArgs e)
        {
            if (grvScore.RowCount > 0)
            {
                DataTable _dtStudentList = new DataTable();
                _dtStudentList = m_data.m_DCReadOnly.Training_Student_Subject_Classes.GetStudentsSubjectClass(
                                                                m_data.m_DCReadOnly.Training_Student_Classes,
                                                                m_data.m_DCReadOnly.Training_Students,
                                                                GetSubjectClassKey()).ToDataTable();
                FrmScore_AddStudentSubjectClassRequired f = new FrmScore_AddStudentSubjectClassRequired(m_gPersonelKey, GetSubjectClassKey(), _dtStudentList);
                f.ShowDialog();
            }
            else
            { }
        }
        #endregion
        #endregion
    }
}
